RE: Why does this work?

Subject: RE: Why does this work?
From: Kevin Williams <Kevin.Williams@xxxxxxxxxxxxxx>
Date: Mon, 7 Aug 2000 13:32:42 -0400
Christian,

position() is based on the order of the axis being tested. The preceding::
axis is defined to be ordered in reverse document order. So, when you say
preceding::row[position()=1], what you're asking for is the row element that
occurs last in document order before the current node - which enables your
stylesheet to work correctly.

Hope this helps...

- Kevin

Kevin Williams
XML Architect
Ultraprise Corporation

> -----Original Message-----
> From: Schmitt, Christian [mailto:Christian.Schmitt@xxxxxxxxxxxxxxxxx]
> Sent: Monday, August 07, 2000 12:27 PM
> To: XSL-List@xxxxxxxxxxxxxxxx
> Subject: Why does this work?
> 
> 
> Hi,
> I have this XML data:
> 
> <rowset>
>  <row>
>   <customer>1</customer>
>   <account>11</account>
>  </row>
>  <row>
>   <customer>1</customer>
>   <account>22</account>
>  </row>
>  <row>
>   <customer>2</customer>
>   <account>33</account>
>  </row>
>   <customer>2</customer>
>   <account>44</account>
>  </row>
> </rowset>
> 
> I want to get output like this:
> 
> <table>
>  <tr>
>   <td>1</td>
>   <td>11</td>
>  </tr>
>  <tr>
>   <td>&nbsp;</td>
>   <td>22</td>
>  </tr>
>  <tr>
>   <td>2</td>
>   <td>33</td>
>  </tr>
>  <tr>
>   <td>&nbsp;</td>
>   <td>44</td>
>  </tr>
> </table>
> 
> I solved it with the following template (this assumes that the data is
> ordered by customer):
> 
> <xsl:template match="row">
>  <xsl:choose>
>   <xsl:when test="customer = preceding::row[position()=1]/customer">
>    <td>&nbsp;</td>
>   </xsl:when>
>   <xsl:otherwise>
>    <td><xsl:value-of select="customer"/>
>   </xsl:otherwise>
>  </xsl:choose>
>  <td><xsl:value-of select="account"/></td>
> </xsl:template>
> 
> Now I'm glad it works, but for some peace of mind I would 
> like to know why 
> <xsl:when test="customer = preceding::row[position()=1]/customer"> 
> behaves as it does?
> 
> 
> Thanks in advance,
> Christian Schmitt
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread