Problem
I'm trying to sort on the entire value of rule/@id where the value of @id is a three value, hyphenated string like this "1-10-12" or "10-15-2". I've tried converting to a number, and I've tried formatting the number, but no luck.
The code sample output sorts by the left-most digits only, the sub-values are out of order.
XML source:
<rule-mapping name="C">
<rule id="0-1-1">
<checker id="checker1"/>
<checker id="checker2"/>
</rule>
<rule id="0-1-10">
<checker id="checker3"/>
</rule>
<rule id="0-1-11">
<checker id="checker4"/>
</rule>
<rule id="15-1-2">
<checker id="checker5"/>
</rule>
<rule id="0-1-12">
<checker id="checker6"/>
</rule>
</rule-mapping>
transform snippet:
<tbody>
<xsl:for-each select="rule-mapping/rule">
<xsl:sort select="substring-before(@id, '-')" data-type="number"/>
<xsl:sort select="substring-after(@id, '-')" data-type="number"/>
<row>
<entry>
<xsl:value-of select="@id"/>
</entry>
<entry>
<xsl:for-each select="checker">
<p>
<codeph><xsl:value-of select="@id"/></codeph><xsl:text> </xsl:text>
</p>
</xsl:for-each>
</entry>
</row>
<xsl:text>
</xsl:text>
</xsl:for-each>
</tbody>
Expected output:
<row>
<entry>0-1-1</entry>
<entry>
<p><codeph>checker1</codeph> </p>
<p><codeph>checker2</codeph> </p>
</entry>
</row>
<row>
<entry>0-1-10</entry>
<entry>
<p>
<codeph>checker3</codeph> </p>
</entry>
</row>
<row>
<entry>0-1-11</entry>
<entry>
<p>
<codeph>checker4</codeph> </p>
</entry>
</row>
<row>
<entry>0-1-12</entry>
<entry>
<p>
<codeph>checker6</codeph> </p>
</entry>
</row>
<row>
<entry>15-1-2</entry>
<entry>
<p>
<codeph>checker5</codeph> </p>
</entry>
</row>
Thanks in advance.
No comments:
Post a Comment