Note that there are some explanatory texts on larger screens.

plurals
  1. POTransforming XML mixed nodes with disable-output-escaping
    primarykey
    data
    text
    <p>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.</p> <p>I have an XML document that contains mixed nodes, e.g.:</p> <pre> &lt;paragraph&gt; This is some text that is &lt;bold&gt;bold&lt;/bold&gt; and this is some that is &lt;italic&gt;italicized.&lt;/italic&gt; &lt;/paragraph> </pre> <p>I would typically use a transformation that looks something like this:</p> <pre> &lt;xsl:template match="bold"&gt; &lt;b&gt;&lt;xsl:apply-templates/&gt;&lt;/b&gt; &lt;/xsl:template&gt; &lt;xsl:template match="italic"&gt; &lt;i&gt;&lt;xsl:apply-templates/&gt;&lt;/i&gt; &lt;/xsl:template&gt; &lt;xsl:template match="paragraph"&gt; &lt;p&gt;&lt;xsl:apply-templates/&gt;&lt;/p&gt; &lt;/xsl:template&gt; </pre> <p>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?</p> <p>This, of course, doesn't work because I would lose the child nodes:</p> <pre> &lt;xsl:template match="paragraph"&gt; &lt;p&gt;&lt;xsl:value-of select="." disable-output-escaping="yes"/&gt;&lt;/p&gt; &lt;/xsl:template&gt; </pre> <p>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).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload