[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Wah? Weird... Clarifying the Schema

Subject: RE: Wah? Weird... Clarifying the Schema
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 28 Oct 2004 08:19:16 +0100
kay wah
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.

Michael Kay
http://www.saxonica.com/

> 
>           <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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.