Why wouldnt it work? All you are telling the processor to do is sort
the result-set of the for-each loop. The resulting sort and the process
of the original node-set being processes are two seperate processes and
should not be confused by the fact that the sort element comes before
the processing logic of the for-each loop. The sort element MUST be the
first child (you can have multiple sort elements but they must follow
each other sequentially w/o any other elements between the first and
last sort element.) of for-each or apply-templates. Would be kind of a
drag if that then meant that the elements were sorted first and then
processed as such. Think:
sort = output in sorted order
and
for-each = processing in document order
And it might help things seem a little more clear.
Hope this helps!
<M:D/>
Michael wrote:
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>
--+------------------------------------------------------------------
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>
--+--