Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 14th, 2005, 08:17 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to sort using xsl sort command

Hi,

I am facing a problem while sorting a particular column of table being displayed. I have tried a couple of options but they seem to be failing. I would appreciate if someone could help me with this.

below mentioned is the sample xml and the xsl extract

Xsl:

<table border="1" class="ssh_exploded" width="100%">
  <tr>
        <th class="ssh_expcode" scope="col">Code</th>
        <th class="ssh_exppart" scope="col">Manufacturing Part#</th>
        <th class="ssh_expdesc" scope="col">Description</th>
  </tr>
  <xsl:for-each select="explode_code">

    <xsl:variable name="sortedElements">
    <xsl:for-each select="descendant-or-self::manufacturing_part">
    <xsl:sort data-type="text" select="supported_machine/explode_code/name"/>
    <xsl:copy-of select="."/>
    </xsl:for-each>
    </xsl:variable>

    <xsl:for-each select="xalan:nodeset($sortedElements)/*">
          <xsl:choose>
                <xsl:when test="@audience='INTERNAL'">
                  <ssh_internal><tr>
                         <td class="ssh_expcode" scope="row" align="center">
                           <xsl:value-of select="preceding-sibling::name| following-sibling::name | supported_machine/explode_code/name" />
                         </td>
                         <xsl:apply-templates select="." mode="exploded" />
                   </tr></ssh_internal>
              </xsl:when>
          </xsl:choose>
        </xsl:for-each>
  </xsl:for-each>
 </table>

The Corresponding XML is :

      <marketing_part audience="ALL">
        <number>X4615A</number>
        <level>x-option</level>
        <type>Exploded</type>
        <description display="no"><![CDATA[Bottom (Slot 1) Filler Panel]]></description>
        <supported_machine>
          <name>Sun Fire 12K</name>
          <replacement_code>NONE</replacement_code>
            <sunstore_id>#540-4166</sunstore_id>
            </references>
            <level>manufacturing</level>
            <type>Exploded</type>
            <description display="yes"><![CDATA[Bottom Slot 0 I/O Filler Panel, Option 4615A]]>
            </description>
            <supported_machine>
              <name>Sun Fire 12K</name>
              <replacement_code>FRU</replacement_code>
              <support_code>O</support_code>
              <explode_code>
                <name>NS</name>
              </explode_code>
            </supported_machine>
          </manufacturing_part>
        </manufacturing>
      </marketing_part>


Please Help !

Regards
Vineet

Reply With Quote
  #2 (permalink)  
Old June 14th, 2005, 08:27 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

Your XML isn't well-formed which makes it difficult to see what's going on.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old June 17th, 2005, 05:45 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

My apologies for submitting a malicious XML, the updated XML mentioned below is well - formed. I would be highly grateful if you could help in resolving this particular issue.

XML :

<?xml version="1.0" encoding="UTF-8"?>
    <manufacturing>
          <manufacturing_part audience="ALL">
            <number>540-4201</number>
            <references>
              <sunstore_id>#540-4201</sunstore_id>
            </references>
            <level>manufacturing</level>
            <type>Exploded</type>
            <description display="yes"><![CDATA[Top Slot 0 Filler Panel, Option 4610A]]></description>
            <supported_machine>
              <name>Sun Fire 12K</name>
              <replacement_code>FRU</replacement_code>
              <support_code>O</support_code>
              <explode_code>
                <name>NS</name>
              </explode_code>
            </supported_machine>
          </manufacturing_part>
        </manufacturing>


and the XSL is :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
  version="1.0"
  media-type="text/html"
  doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  indent="yes"
  encoding="UTF-8" />
<html>
<body>
<xsl:apply-templates select="exploded_view"/>
</body>
</html>
<xsl:template match="exploded_view">
<table border="1" class="ssh_exploded" width="100%">
  <tr>
        <th class="ssh_expcode" scope="col">Code</th>
        <th class="ssh_exppart" scope="col">Manufacturing Part#</th>
        <th class="ssh_expdesc" scope="col">Description</th>
  </tr>
  <xsl:for-each select="explode_code">

    <xsl:variable name="sortedElements">
    <xsl:for-each select="descendant-or-self::manufacturing_part">
    <xsl:sort data-type="text" select="supported_machine/explode_code/name"/>
    <xsl:copy-of select="."/>
    </xsl:for-each>
    </xsl:variable>

    <xsl:for-each select="xalan:nodeset($sortedElements)/*">
          <xsl:choose>
                <xsl:when test="@audience='INTERNAL'">
                  <ssh_internal><tr>
                         <td class="ssh_expcode" scope="row" align="center">
                           <xsl:value-of select="preceding-sibling::name| following-sibling::name | supported_machine/explode_code/name" />
                         </td>
                         <xsl:apply-templates select="." mode="exploded" />
                   </tr></ssh_internal>
              </xsl:when>
          </xsl:choose>
        </xsl:for-each>
  </xsl:for-each>
 </table>



Thanks and Regards
Vineet

Reply With Quote
  #4 (permalink)  
Old June 17th, 2005, 06:15 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

<xsl:for-each select="explode_code">

    <xsl:variable name="sortedElements">
    <xsl:for-each select="descendant-or-self::manufacturing_part">


In your sample data, the explode_code element does not have any descendant-or-self manufacturing_part elements, so there isn't going to be any data to sort.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 03:10 PM
DataGrig doesn't remeber sort command ysiline ASP.NET 1.0 and 1.1 Basics 0 April 12th, 2006 12:55 AM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
XSLT-- xsl:sort help... debo XSLT 2 December 3rd, 2004 04:25 PM
xsl:sort and IE 5.0 Issue babloo81 XSLT 1 March 17th, 2004 06:12 AM



All times are GMT -4. The time now is 05:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.