Hi Kief,

I've studied the quirks of XPath and found it nice and solidly specified
with a good list of examples in the w3c.org spec.

So here a quick course to lead to a simple solution for you:
"//subproject/text()" selects all subproject decendant names.
"//component[subproject=$name]" selects the components by subproject name.

so you can simple nest two loops in your .dvsl file:

## create empty ArrayList to accumulate processed subproject names to avoid repetitions
#set( $processed = [] )

<h1>Listing by Subproject</h1>

#tableStart()

  ## select all subproject names (will contain repetitions)
  #foreach( $subproject in $node.selectNodes("/component/subproject/text()") )

    ## skip repetitions
    #if( ! $processed.contains($subproject) )

      ## store in the processed list
      #set( $dummy = $processed.add($subproject) )
<tr>
  <td colspan="4">
    <h2>$subproject Subproject</h2>
  </td>
</tr>

      #foreach( $comp in $node.selectNodes("//component[subproject=$subproject]" )
        $context.applyTemplates($comp)
      #end

    #end

  #end

#tableEnd()


This is untested but braincompiled and braintraced code. It should work if 
Murphy didn't hit.

I've not yet found a simple solution on how to select a nodelist without 
repetitions. So the ArrayList.contains() trick is the most straightforward
workaround because it does not require a $tool (using a hash).

Cheers,
Christoph

Kief Morris wrote:
>[snip] 
> Ideally things like subproject would be separate tags, e.g.
> 
>         <component name="Digester">
>                 <subproject>Commons</subproject>
>                 <what>Parse XML into Objects</what>
>                 <where>Digester package</where>
>                 ...
>         </component>
> 
> My .dvsl file does this:
> 
> <h1>Listing by Subproject</h1>
> 
> #tableStart()
> 
>         #foreach ($component in $node.selectNodes("//component[@subproject]"))
>                 #set($dummy = 
>$context.toolbox.subprojects.put($component.attrib("subproject"), $component))
>         #end
>         #foreach($subproject in $context.toolbox.subprojects.keySet())
> <tr>
>         <td colspan="4">
>                 <h2>$subproject Subproject</h2>
>         </td>
> </tr>
> 
>                 #set ($complist = 
>$node.selectNodes("//component[@subproject='$subproject']"))
>                 #foreach ($comp in $complist)
>                         $context.applyTemplates($comp)
>                 #end
>         #end
> 
> ... it does something similar to list the data in different ways. It first builds a 
>list of unique
> "subproject" attribute values by inserting them into a HashSet (kept in the toolbox 
>with the
> name "subprojects"), and then iterates over each of these and renders a table entry 
>for
> each <component> node with that subproject.
> 
> So, an admittedly cosmetic improvement would be to figure out how to grab those 
>subproject
> names if they were child tag values, as I described above. I guess this is an xpath 
>question.

-- 
:) Christoph Reck

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to