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 June 14th, 2005, 07: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

 
Old June 14th, 2005, 07:27 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

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
 
Old June 17th, 2005, 04: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

 
Old June 17th, 2005, 05:15 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

<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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
DataGrig doesn't remeber sort command ysiline ASP.NET 1.0 and 1.1 Basics 0 April 11th, 2006 11:55 PM
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





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