This can be accomplished if you set the output method
to text
.
This transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="char">
<xsl:value-of select="concat('&#x', /char/@hex, ';', '')"/>
</xsl:template>
</xsl:stylesheet>
When applied on the provided XML document:
<char hex="AB"/>
produces the wanted result:
«
Of course, with the text
output method one needs to produce the individual characters of starting and ending tags (<xsl:copy>
, <xsl:copy-of>
, <xsl:element>
and literal result elements do not produce any tags in this output method), but with some patience, everything is possible.
One could also use DOE (Disable Output Escaping), but this "feature" is not mandatory in the XSLT Spec. and some XSLT processors (including, I think, the one used by FF) don't implement DOE.
Probably the best solution (not using method="text"
) is the following:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my" exclude-result-prefixes="my"
>
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="us-ascii"/>
<my:hex>
<code start="8">€‚ƒ„…†‡ˆ‰Š‹ŒŽ</code>
<code start="9">‘’“”•–—˜™š›œžŸ</code>
<code start="A"> ¡¢£¤¥¦§¨©ª«¬­®¯</code>
<code start="B">°±²³´µ¶·¸¹º»¼½¾¿</code>
<code start="C">ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ</code>
<code start="D">ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß</code>
<code start="E">àáâãäåæçèéêëìíîï</code>
<code start="F">ðñòóôõö÷øùúûüýþÿ</code>
</my:hex>
<xsl:variable name="vHex" select="document('')/*/my:hex/*"/>
<xsl:template match="char">
<xsl:variable name="vchar1" select="substring(@hex,1,1)"/>
<xsl:variable name="vchar2" select="substring(@hex,2,1)"/>
<xsl:variable name="voffset">
<xsl:choose>
<xsl:when test="number($vchar2)">
<xsl:value-of select="$vchar2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count($vHex[@start = $vchar2]/preceding-sibling::*)+9"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="substring($vHex[@start=$vchar1], $voffset, 1)"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the provided XML document:
<char hex="AB"/>
the wanted result is produced:
«
This assumes that the values of the hex
attribute are hexadecimals in the range x80 to xFF. If it is necessary to have values in a wider range, such as x00 to XFF, more code
elements need to be accordingly added to the my:hex
element