[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: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Fri, 19 Apr 2002 13:25:14 -0400
xsl sort last
Hello,

They shouldn't sort the same.

In Version1 you're matching on the document root, then rolling through a
list of addressbook/address elements sorted by name/last-name child
elements.

In Version2 your matching on the addressbook/address element directly and
not rolling through them as list, your for-each will only execute one time
because within the given template you only have one addressbook/address
element ... you should get many, un-sorted, <p> elements.


What you may want to try is this:

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

or, if you're worried about only finding addressbook elements with address
children:

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

HTH,
Jeff


-----Original Message-----
From: Dung, Ming-tzung [mailto:Ming-tzung_Dung@xxxxxxxxxxxxx]
Sent: Friday, April 19, 2002 12:54 PM
To: XSLT List (E-mail)
Subject:  <xsl:sort> question.


   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!!
------
**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.