?
Solved

XSL OrderBy problem ?

Posted on 2003-03-17
5
Medium Priority
?
229 Views
Last Modified: 2012-08-13
In my XSL file I am using the following command...

<xsl:for-each select="ProductGroups/Group" order-by="field[@id='OrderNo']">

That is I am displaying the records in the order of OrderNo...
But it displays records in the following order...1,10,12,13,14,15,2,3,4,5

How can i get the proper order ...(1,2,3,4,5,10,12,13,14,15) ?
0
Comment
Question by:Amita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 8151284
Might I sugest that you move up to xsl 1.1 and use xsl:sort? The stylesheet reference for the latest standard is :-

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">


you would then write :-

<xsl:for-each select="ProductGroups/Group">
   xsl:sort select="field[@id='OrderNo']"/>
0
 

Accepted Solution

by:
Nazgyl earned 150 total points
ID: 8153550
It looks like its sorting your @id as a string, not as numbers.

Try what BigRat suggested with the <xsl:sort>, but put in the data-type attribute :

<xsl:for-each select="ProductGroups/Group">
<xsl:sort select="field[@id='OrderNo']" data-type="number" />
0
 

Author Comment

by:Amita
ID: 8165838
I changed the code like this....In place of

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

now I am writing the following..

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

and using this code...

<xsl:for-each select="ProductGroups/Group">
<xsl:sort select="field[@id='OrderNo']"/>

but ist giving weird results...not displaying the page and its contents... and not even giving any error....what could be the problem ?



0
 
LVL 27

Expert Comment

by:BigRat
ID: 8166142
I wonder whether you might post both the XML and the XSL? Quite often a minor error in editing causes really weird results, and I'd like to see the extract structure of the XML document so as to get the node addressing correct.
0
 

Author Comment

by:Amita
ID: 8171785
The xml file named as "ProductGroupsNew.xml" is as follows
The structure has distorted a bit b'coz of copy and paste......."ProductGroups" is the root node...."Group" is the child node..

<?xml version="1.0" ?>
- <ProductGroups>
 - <Group>
  - <field id="ProdGroupId">
     <field_value>17</field_value>
    </field>
  - <field id="ProdGroupName">
     <field_value>System Generation &  Efficiency</field_value>
    </field>
  - <field id="ProdGroupImage">
     <field_value>p1.jpg</field_value>
    </field>
  - <field id="Description">
     <field_value>good</field_value>
    </field>
  - <field id="Url">
     <field_value>www.msn.com</field_value>
    </field>
  - <field id="OrderNo">
     <field_value>1</field_value>
    </field>
 </Group>
 - <Group>
  - <field id="ProdGroupId">
  <field_value>18</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>System Distribution & Utilisation</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p2.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>abcl</field_value>
  </field>
- <field id="Url">
  <field_value>www.rediff.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>2</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>20</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Valves</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p5.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>nice</field_value>
  </field>
- <field id="Url">
  <field_value>www.cricket365.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>4</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>21</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Control Valves New</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p6.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>satisfied</field_value>
  </field>
- <field id="Url">
  <field_value>www.google.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>5</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>22</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Desuperheaters</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value />
  </field>
- <field id="Description">
  <field_value>excelent</field_value>
  </field>
- <field id="Url">
  <field_value>www.altavista.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>6</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>23</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Stations</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p8.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>wonderfull</field_value>
  </field>
- <field id="Url">
  <field_value>www.lycos.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>7</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>24</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Flowmetering</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p9.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>beautiful</field_value>
  </field>
- <field id="Url">
  <field_value>www.cricketzone.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>8</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>25</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Level Measurement</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p10.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>flamboyent</field_value>
  </field>
- <field id="Url">
  <field_value>www.jguru.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>9</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>26</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Flow Switches</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p11.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>flabagasted</field_value>
  </field>
- <field id="Url">
  <field_value>www.switches.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>10</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>28</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Controllers</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p13.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>can't explain</field_value>
  </field>
- <field id="Url">
  <field_value>www.comtrollers.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>12</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>29</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>Control Systems</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value>p14.jpg</field_value>
  </field>
- <field id="Description">
  <field_value>moderate</field_value>
  </field>
- <field id="Url">
  <field_value>www.quickSpeed.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>13</field_value>
  </field>
  </Group>
- <Group>
- <field id="ProdGroupId">
  <field_value>30</field_value>
  </field>
- <field id="ProdGroupName">
  <field_value>pneumatic</field_value>
  </field>
- <field id="ProdGroupImage">
  <field_value />
  </field>
- <field id="Description">
  <field_value />
  </field>
- <field id="Url">
  <field_value>www.pneumatics.com</field_value>
  </field>
- <field id="OrderNo">
  <field_value>14</field_value>
  </field>
  </Group>
 </ProductGroups>

The xsl file "ProductGroupsNew.xsl" is :

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
 <xsl:template match="/">
  <HTML>
  <table cellpadding="2" cellspacing="0" border="1" bordercolor="#808080" width="100%"   style="border-collapse: collapse">
<tr bgcolor="#B4B4B4">
      <th bordercolor="#808080">
            <font face="arial,helvetica" size="2" color="#FFFFFF">Order No</font>
      </th>
      <th bordercolor="#808080">
            <font face="arial,helvetica" size="2" color="#FFFFFF">Name</font>
      </th>
      <th bordercolor="#808080">
            <font face="arial,helvetica" size="2" color="#FFFFFF">Url</font>
      </th>
      <th bordercolor="#808080">
            <font face="arial,helvetica" size="2" color="#FFFFFF">Image</font>
      </th>
      <th bordercolor="#808080">
            <font face="arial,helvetica" size="2" color="#FFFFFF">Update Order</font>
      </th>
      <th bordercolor="#808080"><font face="arial,helvetica" size="2" color="#FFFFFF">Edit</font></th>
      <th bordercolor="#808080"><font face="arial,helvetica" size="2" color="#FFFFFF">Delete</font></th>
</tr>
<xsl:for-each select="ProductGroups/Group" order-by="-field[@id='OrderNo']">
<tr>
      <td>
            <font face="arial" size="2">
            <xsl:value-of select="field[@id='OrderNo']/field_value"/>
            </font>
      </td>
      <td>
            <font face="arial" size="2">
            <xsl:value-of select="field[@id='ProdGroupName']/field_value"/>
            </font>
      </td>
      <td>
            <font face="arial" size="2">
            <xsl:value-of select="field[@id='Url']/field_value"/>
            </font>
      </td>
      <td>
            <img>
            <xsl:attribute name="src">../../images/prodgroups/<xsl:value-of select="field[@id='ProdGroupImage']/field_value"/></xsl:attribute>
            </img>
      </td>
      <td>
            
      </td>
      <td align="center">
            <a>
            <xsl:attribute name="href">editProdGroup.asp?id=<xsl:value-of select="field[@id='ProdGroupId']/field_value"/></xsl:attribute>
            <img>
            <xsl:attribute name="src">../../images/editicon.gif</xsl:attribute>
            <xsl:attribute name="border">0</xsl:attribute>
            </img>
            </a>
      </td>
      <td align="center">
            <a>
            <xsl:attribute name="href">deleteProdGroup.asp?id=<xsl:value-of select="field[@id='ProdGroupId']/field_value"/></xsl:attribute>
            <img>
            <xsl:attribute name="src">../../images/trash.gif</xsl:attribute>
            <xsl:attribute name="border">0</xsl:attribute>
            </img>
            </a>
      </td>
</tr>
</xsl:for-each>
</table>
  </HTML>
  </xsl:template>
</xsl:stylesheet>

And in an asp file I have put the following code...

<%
  sourceFile = Server.MapPath("ProductGroupsNew.xml")
  styleFile = Server.MapPath("ProductGroupsNew.xsl")
 
  set source = Server.CreateObject("Microsoft.XMLDOM")
  source.async = false
  source.load(sourceFile)
  set style = Server.CreateObject("Microsoft.XMLDOM")
  style.async = false
  style.load(styleFile)
  Response.Write source.transformNode(style)
%>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question