Displaying output based on attribute value of xml tag




<?xml version="1.0" encoding="UTF-8"?>

<provinces>
<name num="5">Alberta</name>
<name num="3">British</name>
<name num="1">Manitoba</name>
<name num="4">New Brunswick</name>
<name num="2">Newfoundland</name>
</provinces>


I want output as



1. Manitoba
2. Newfoundland
3. British
4. New Brunswick
5. Alberta


I am using the following xslt



<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="text" />

<xsl:template match="provinces">
<xsl:apply-templates select="name" />
</xsl:template>

<xsl:template match="name">
<xsl:value-of select="position()" />
<xsl:text>. </xsl:text>
<xsl:value-of select="." />
</xsl:template>

</xsl:stylesheet>


I know this way of doing does not give my desired output but this is how far I got.


I want to position them based on the attribute "num" value how do I do that?


No comments:

Post a Comment