[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: <xsl:sort> question.
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
|
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
|