for example i have following xml input:
<Letter>
<LetterProductInfo>
<Paragraph>
<DisplayOrder>
20
</DisplayOrder>
<Text>
text abc
</Text>
</Paragraph>
</LetterProductInfo>
</Letter>
<Letter>
<LetterProductInfo>
<Paragraph>
<DisplayOrder>-10</DisplayOrder>
<Text>
text kkk
</Text>
</Paragraph>
</LetterProductInfo>
</Letter>
<Letter>
<LetterProductInfo>
<Paragraph>
<DisplayOrder>-20</DisplayOrder>
<Text>
text xyz
</Text>
</Paragraph>
</LetterProductInfo>
</Letter>
i need help as to write xsl so that it will loop through all letter nodes and select the Text Based on the DisplayOrder’s value [ I can’t hardcode since i will not know what will the the displayorder id, all i know is that is an integer value]
something like:
<xsl:for-each select="Letter">
<!--
missing logic so that xsl:value-of select="?" will print
1. test xyz - because its DisplayOrderId is -20
2. text kkk - because its DisplayOrderId is -10
3. text abc - because its DisplayOrderId is 20
-->
</xsl:for-each>
Thanks.
If I understand well your question, you want to output a certain string such as:
for each Letter, but you want Letter elements sorted based on the numerical value of DisplayOrder.
xsl:sort does that for you:
Or you can as well do:
I suggest you RTFM about xsl:sort at http://www.w3.org/TR/xslt20/#xsl-sort
My code here assumes there’s only 1 node returned by LetterProductInfo/Paragraph/DisplayOrder.
NB: for your next question, you might want to be more specific about what you expect as output. I assume you just want string and not HTML, for instance.