I’m trying to sort values from a XML file in a HTML tag with , my code looks like this:
<option value="{id/value}">
<xsl:value-of select="short_name/value" >
<xsl:sort select="short_name/value"/>
</xsl:value-of>
</option>
Where do I have to put the tag here? I only get an java.io.IOException: com.caucho.xsl.XslParseException.
The should just be ordered by the shortname/value from the XML file.
The xsl:value-of is not allowed to contain any next xsl elements, like xsl:sort. The sort command only really applies either for xsl:for-each or xsl:apply-templates.
Or, as it is preferable to use templates over for-each, you could do this
You wouldn’t need a matching template for the value element unless you wanted to output anything other than the text value, as the default behaviour of the XSLT processor will be output the text in this case.
One thing to note, is that in your sample, you will only ouptut one option element. Are you sure you don’t want multiple ones, one for each id or short_name. It depends on your XML input sample, of course, but suppose you had XML like this
Then, if you use the following XSLT
Then the following is output