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

Re: <xsl:sort> question.

Subject: Re: <xsl:sort> question.
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 13:33:09 -0400
xsl sort get first
[Dung, Ming-tzung]

>    The version 1 will work and the version 2 will not sort the data, even
> though I think that these two are logically equivalent.
>   Please let me know what you think?  Thanks in advance!!

They are not the same.  In version 1, the template gets instantiated once.
The four addressbook/address elements then get processed by the for-each.

In version 2, the template gets instantiated for each separate
/addressbook/address element, for a total of four times in your example.
Each time, the for-each gets applied to the current node, which consists of
a single address node.  So there is nothing to sort.

You can demonstrate this by adding a visible marker so you can see when the
template has been instantiated, like this

  <xsl:template match="/addressbook/address">
    --template called --
    <xsl:for-each select=".">
      <xsl:sort select="name/last-name"/>
      <p>
      <xsl:value-of select="name/last-name"/>
      </p>
    </xsl:for-each>
    </html>
  </xsl:template>

You will see the marker once for version 1, four times for version 2.

Cheers,

Tom P

> ------
> **Version1 - output the sorted last name**
> <xsl:template match="/">
>      <xsl:for-each select="addressbook/address">
>       <xsl:sort select="name/last-name"/>
>       <p>
>       <xsl:value-of select="name/last-name"/>
>       </p>
>     </xsl:for-each>
> </xsl:template>
>
> **Version 2 - output the sorted last name**
>   <xsl:template match="/addressbook/address">
>     <xsl:for-each select=".">
>       <xsl:sort select="name/last-name"/>
>       <p>
>       <xsl:value-of select="name/last-name"/>
>       </p>
>     </xsl:for-each>
>   </xsl:template>
>
> **Input xml data
> -----
> <?xml version="1.0"?>
> <addressbook>
>   <address>
>     <name>
>       <title>Mr.</title>
>       <first-name>Chester Hasbrouck</first-name>
>       <last-name>Frisby</last-name>
>     </name>
>   </address>
>   <address>
>     <name>
>       <first-name>Harry</first-name>
>       <last-name>Backstayge</last-name>
>     </name>
>   </address>
>   <address>
>     <name>
>       <first-name>Mary</first-name>
>       <last-name>McGoon</last-name>
>     </name>
>   </address>
>   <address>
>     <name>
>       <title>Ms.</title>
>       <first-name>Amanda</first-name>
>       <last-name>Reckonwith</last-name>
>     </name>
>   </address>
> </addressbook>
> -----
>
> Ming
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.