xsl-list
[Top] [All Lists]

Re: [xsl] Help on node selection

2010-08-27 11:42:37
 On 8/27/2010 6:42 AM, Fabien Tillier wrote:
I want to first process nodes which have N1 = 1, then nodes with N1=2. But I 
want to call the template only once with all matching nodes (so once with 
N1=1 nodes, and once with N1=2 nodes), because I am building a group from 
these
Thus, I have tried with 

<xsl:apply-templates select="//row[N1=1]" mode="headers"/>

But my template

<xsl:template match="row" mode="headers">
                Headers              
</xsl:template>

Is called on each matching node...(thus 3 times here), rather than once, and 
then gets some loop to individually treat each node from the list.
How can I proceed ?

If you are using XSLT 2.0, your outer template can say
<myDoc>
<xsl:for-each-group select="//row" group-by="N1">
  <!-- this loop body is instantiated once for each group, e.g. N1=1 -->
  <xsl:element name="N1is{N1}">
    <xsl:for-each select="current-group()">
       <!-- this inner loop body is instantiated once for each row of
the N1=1 group -->
       <xsl:value-of select="N2" />,
    </
  </
</
</myDoc>

And you get output like
<myDoc>
  <N1is1>120, 120, 110</N1is1>
  <N1is2>120, 120</N1is2>
</myDoc>

(untested)

Is that clearer?

Lars


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>