Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2006, 01:09 AM
Registered User
 
Join Date: Apr 2006
Location: , , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sakubar Sathik Send a message via Yahoo to Sakubar Sathik
Default Sorting element in xsl

Is it possible to sort two elements within a same for-each loop?

Sathik Khan
 
Old April 6th, 2006, 03:45 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Is it possible to sort two elements within a same for-each loop?

Sure, you can sort any number of elements in a for-each loop.

But that's so obvious, I must have misunderstood the question. Please be a bit more specific.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 6th, 2006, 03:58 AM
Registered User
 
Join Date: Apr 2006
Location: , , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sakubar Sathik Send a message via Yahoo to Sakubar Sathik
Default

I have two xml element let say user id and user name in an xml file. when transforming the xml file i want to sort these two elements.

Sathik Khan
 
Old April 6th, 2006, 04:03 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think it would be clearer if you showed a sample of your input and desired output.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 6th, 2006, 04:10 AM
Registered User
 
Join Date: Apr 2006
Location: , , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sakubar Sathik Send a message via Yahoo to Sakubar Sathik
Default

xml file
========
<?xml version="1.0" encoding="ISO-8859-1"?>

<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Vande Madaram</title>
        <artist>AR Rahman</artist>
        <country>India</country>
        <company>Star</company>
        <price>9.90</price>
        <year>2002</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>

xsl file
========
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>

<xsl:template match="/">

  <html>
  <body>
 <table>
<tr>
    <table cellspacing="0" cellpadding="4" rules="all" bordercolor="#3366CC" border="1" id="dgReqList" style="background-color:White;border-color:#3366CC;border-width:1px;border-style:None;border-collapse:collapse;">
      <xsl:variable name="count" select="0"/>
      <xsl:for-each select="catalog/cd">
      <xsl:sort select="title"/>
      <tr>
    <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="author"/></td>
      </tr>
      </xsl:for-each>
    </table></tr> </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>


Sathik Khan
 
Old April 6th, 2006, 04:23 AM
Registered User
 
Join Date: Apr 2006
Location: , , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sakubar Sathik Send a message via Yahoo to Sakubar Sathik
Default

did u finished Michael


Regards,
Sathik Khan




Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a list by the third element Devlin C# 2008 aka C# 3.0 5 March 12th, 2008 10:47 AM
XSL(T) problems with xsl:element pan69 XSLT 3 December 13th, 2007 06:24 AM
xsl sorting ramuis78 XSLT 0 June 9th, 2006 01:51 PM
XSL Sorting using variable mannabaron XSLT 4 February 15th, 2006 06:13 AM
Sorting with XSL mannabaron XSLT 2 February 14th, 2006 10:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.