How do you write the attributes of an element in a specific order without writing them explicitly?
Consider:
<xsl:template match="Element/@1|@2|@3|@4"> <xsl:if test="string(.)"> <span> <xsl:value-of select="."/><br/> </span> </xsl:if> </xsl:template>
Attributes should be displayed in the order 1, 2, 3, 4 . Unfortunately, you cannot guarantee the order of attributes in XML, it can be <Element 2="2" 4="4" 3="3" 1="1">
So the above template will give the following:
<span>2</span> <span>4</span> <span>3</span> <span>1</span>
Ideally, I don't want to check every attribute if it got a value. I was wondering if I can somehow adjust the display order? Or I need to do this explicitly and repeat 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>
What can be done in this case?
source share