This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Why does this work?
- To: XSL-List at mulberrytech dot com
- Subject: Why does this work?
- From: "Schmitt, Christian" <Christian dot Schmitt at dresdner-bank dot com>
- Date: Mon, 7 Aug 2000 18:27:28 +0200
- Reply-To: xsl-list at mulberrytech dot com
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> </td>
<td>22</td>
</tr>
<tr>
<td>2</td>
<td>33</td>
</tr>
<tr>
<td> </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> </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