Hello everyone,
I was wondering if there is a way of displaying element's attributes in a specific order, with a use of sequence or somehow establishing an order rather than writing it explicitly.
Sorry, explanation is a bit unclear. The example might help:
So I have a template:
<xsl:template match="Element/@1|@2|@3|@4">
<xsl:if test="string(.)">
<span>
<xsl:value-of select="."/><br/>
</span>
</xsl:if>
</xsl:template>
And I want attributes to appear in the order 1, 2, 3, 4. Unfortunately, you can't garantee the order of attributes in XML, it could be <Element 2="2" 4="4" 3="3" 1="1">
So the template above will produce the following:
<span>2</span>
<span>4</span>
<span>3</span>
<span>1</span>
Ideally I don't want to test each attribute if it has got a value. I was wondering if I can somehow set an order of my display? Or will I need to do it explicitly and repeating the if test as in:
<xsl:template match="Element">
<xsl:if test="string(./@1)>
<span>
<xsl:value-of select="./@1"/><br/>
</span>
</xsl:if>
...
<xsl:if test="string(./@4)>
<span>
<xsl:value-of select="./@4"/><br/>
</span>
</xsl:if>
</xsl:template>
Would be interesting to know what can be done in this case.
Many thanks!