[xsl] Wah? Weird... Clarifying the Schema
Subject: [xsl] Wah? Weird... Clarifying the Schema
From: Michael <msell@xxxxxxxxxxxxxxx>
Date: Thu, 28 Oct 2004 12:21:34 +1000
|
I've come across the strangest thing, and I'm trying to figure out why
it occurs. I was hoping someone would enlighten me onto what is going on
here:
I'm a recent member to the XSLT scene, so don't completely understand
how the schema works to a full extend (i'm learning... slowly (grin)).
Anyway, recently i've been playing around with some code that increments
through each book in a catalog, and displays each book category from the
catalog in a drop down box. To do this I decided to sort the catalog,
incrementally go through each book node, then call a conditional
statement that would only fire off if the previous node had a category
that was different.
The weirdest thing happens here. Firstly, it has come to my attention
that the 'preceding-sibling' axis is not effected by an 'xsl:sort'
element. This is proved when removing the 'xsl:sort' element completely.
The weird thing is that the code WORKS!!! So, i'm hoping I can get some
clarification on this....
Why is the code working?
<xsl:for-each select="catalog/book">
<xsl:sort select="category" data-type="text"
order="ascending" />
<xsl:if test="not(preceding-sibling::book/category = category)">
<xsl:choose>
<xsl:when test="category = $category">
<option value="{category}"
selected="true"><xsl:value-of select="category" /></option>
</xsl:when>
<xsl:otherwise>
<option value="{category}"><xsl:value-of
select="category" /></option>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>