[XSL-LIST Mailing List Archive Home]
[Reply To This Message]
Re: Wah? Weird... Clarifying the Schema
Subject: Re: Wah? Weird... Clarifying the Schema|
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Thu, 28 Oct 2004 00:56:49 -0700
Hey Dr. Kay...
Thanks for the clarification on this. Looks like I need to go back and
reread the spec in regards to the sort element as I obviously have
developed an understanding which is incorrect.
Michael Kay wrote:
A node exists at a particular place in a tree. Sorting changes the order in
which nodes are processed, but it doesn't modify the tree, and therefore the
axes (which navigate the tree) are unaffected by sorting.
Why is the code working?
Because XSLT sorting is defined to be stable.
You are sorting the books by category, and then outputting the first book in
each category. The rules for XSLT sorting say that duplicates retain their
original order, so the first book in a category after sorting is the same as
the first book in the category before sorting.
Actually, looking at it again, it would work even if sort order wasn't
stable, because the only property of a book that you are outputting is the
category, which of course is the same for all the books in a category.
<xsl:sort select="category" data-type="text"
test="not(preceding-sibling::book/category = category)">
<xsl:when test="category = $category">
selected="true"><xsl:value-of select="category" /></option>
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format