Question

Here is my XSLT file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="a/b" />
</xsl:template>
</xsl:stylesheet>

Here is my XML file:

<a><b>four &lt; five</b></a>

I would like the output

four < five

but I get

four

Clearly there is a problem with XSLT understanding the &lt; entity. I have read this question

but do not find it quite relevant because it pertains to the xsl:text tag, whereas I am interested in the xsl:value-of tag.

By the way, I am unable to modify the XML file.

Was it helpful?

Solution

This is most likely w3schools being not up to a good standard. If you enter <a><b>four &amp;lt; five</b></a> you will should get your expected output, although this is not the correct thing to do!

Using &lt; as the entity is the correct thing to do in the XML. And when the resultant XML gets serialised, it should also be output as &lt;

Try it at xmlplayground.com or xsltransform.net and you will see there is actually no problem with your code at all.

As an aside, if you are intending to show the results in the browser, you should probably add the xsl:output statement to indicate you are outputting HTML. (And to stop the <?xml version="1.0" encoding="utf-8"?> declaration being output).

<xsl:output method="html" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top