sirtam
asked on
Read data backwards
Hi,
I want to display the following XML using XSLT:
<root>
<no_of_entries>4</no_of_en tries>
<data>
<number>1</number>
</data>
<data>
<number>2</number>
</data>
<data>
<number>3</number>
</data>
<data>
<number>4</number>
</data>
</root>
For this I would use:
<xsl:for-each select="data">
<xsl:value-of select="number" />
</xsl:for-each>
and have the data printed "1 2 3 4".
I want to have this data read backwards "4 3 2 1". It is not possible to change the XML.
Please advice
SirTam
I want to display the following XML using XSLT:
<root>
<no_of_entries>4</no_of_en
<data>
<number>1</number>
</data>
<data>
<number>2</number>
</data>
<data>
<number>3</number>
</data>
<data>
<number>4</number>
</data>
</root>
For this I would use:
<xsl:for-each select="data">
<xsl:value-of select="number" />
</xsl:for-each>
and have the data printed "1 2 3 4".
I want to have this data read backwards "4 3 2 1". It is not possible to change the XML.
Please advice
SirTam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I noticed that all of the attributes was needed. I used the following sort:
<xsl:sort select="number" order="descending"/>
I now also see that my the data always will be numbered from 1 and up with 1 as min and 4 as max.
<xsl:sort select="number" order="descending"/>
I now also see that my the data always will be numbered from 1 and up with 1 as min and 4 as max.
nope, you need all attributes in this case
<xsl:sort select="number" order="descending"/>
is equal to
<xsl:sort select="position()" order="descending" data-type="text" />
(text is the default, not number)
XSLT1 processors will cast the position() to a string and sort stringwise
If you would have more than 10 items, 10 will be sorted in between 1 and 2
and that is NOT the effect you want, please stick to the original answer
<xsl:sort select="number" order="descending"/>
is equal to
<xsl:sort select="position()" order="descending" data-type="text" />
(text is the default, not number)
XSLT1 processors will cast the position() to a string and sort stringwise
If you would have more than 10 items, 10 will be sorted in between 1 and 2
and that is NOT the effect you want, please stick to the original answer
ASKER
You do have a point here.
In this case there wont be numbers up to 10, so I wouldn't have noticed it. But if the system should be changed this could have made an awkward bug,
Thanks again
In this case there wont be numbers up to 10, so I wouldn't have noticed it. But if the system should be changed this could have made an awkward bug,
Thanks again
ASKER
SirTam