Variations on this question have been posted, but I couldn't find any that address the base case. I thought it would be good to have a canonical answer to the simplest version of the problem. This question assumes xslt 1.0.
I have an XML document that contains mixed nodes, e.g.:
<paragraph> This is some text that is <bold>bold</bold> and this is some that is <italic>italicized.</italic> </paragraph>
I would typically use a transformation that looks something like this:
<xsl:template match="bold"> <b><xsl:apply-templates/></b> </xsl:template> <xsl:template match="italic"> <i><xsl:apply-templates/></i> </xsl:template> <xsl:template match="paragraph"> <p><xsl:apply-templates/></p> </xsl:template>
which works great until I want to use disable-output-escaping="yes", which is an attribute of xsl:value-of. Is there a way to select the text-portion of the mixed node to which I can apply the value-of independent of the embedded nodes?
This, of course, doesn't work because I would lose the child nodes:
<xsl:template match="paragraph"> <p><xsl:value-of select="." disable-output-escaping="yes"/></p> </xsl:template>
I know the fact I am trying to do this probably represents an inherent problem in the way I am handling the XML, but much of the XML is being fairly-naively generated by (trusted) user input, and I am trying to avoid a lot of extra processing code between the XML->XSLT->HTML form (if possible).
If I understand you right, you want text nodes to come out as literal text (
disable-output-escaping="yes"
), but the rest of the transformation should work normally (<bold>
to<b>
etc.)Template modes can help:
I had a similar scenario to deal with (processing nodes with mixed text and node content); this really helped: XSLT mixed content node