[XML-SIG] Entity tralation in XSLT
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Wed, 15 Nov 2000 00:52:05 +0100
> Because I need it ("<") in templates - I'm building complex
> structures. "<" needs to be specified this way (AFAIK) to
> differentiate between this and the start of a tag.
=46rom http://www.w3.org/TR/xslt.html#literal-result-element
# In a template, an element in the stylesheet that does not belong to
# the XSLT namespace and that is not an extension element (see [14.1
# Extension Elements]) is instantiated to create an element node with
# the same expanded-name. The content of the element is a template,
# which is instantiated to give the content of the created element
# node. The created element node will have the attribute nodes that
# were present on the element node in the stylesheet tree, other than
# attributes with names in the XSLT namespace.
So if you want a <magic> element in the output, you should write
<?xml version=3D"1.0"?>
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" version=
=3D"1.0">
<xsl:template match=3D"/">
<magic><xsl:value-of select=3D"//magic"/></magic>
</xsl:template>
</xsl:stylesheet>
OTOH, if you want a less-than character in the output, you should
write < in the template. However, in the output, < *is* a
less-than character, since the output is also XML. From XSLT spec:
# Note that text is processed at the tree level. Thus, markup of <
# in a template will be represented in the stylesheet tree by a text
# node that includes the character <. This will create a text node in
# the result tree that contains a < character, which will be
# represented by the markup < (or an equivalent character
# reference) when the result tree is externalized as an XML document
# (unless output escaping is disabled as described in [16.4 Disabling
# Output Escaping]).
Seems pretty unambiguous to me.
Regards,
Martin