Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

XSL OrderBy problem ?

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
Amita
Asked:
Amita
  • 2
  • 2
1 Solution
 
BigRatCommented:
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
 
NazgylCommented:
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
 
AmitaAuthor Commented:
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
 
BigRatCommented:
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
 
AmitaAuthor Commented:
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now