Storing html tags in xsl variable

Sorry if this is a stupid question, but can you save and extract the HTML fragment in the xsl 1.0 variable? EG:

<xsl:variable name="something"><p>Hi there</p><p>How are you today?</p></xsl:variable>

<xsl:value-of disable-output-escaping="yes" select="$something"/>

It's just that when I try, it seems to strip HTML tags. Thank.

+1
source share
2 answers

You need to use <xsl:copy-of select="$something"/>instead xsl:value-of.

+9
source

I will add some explanation of what is happening :)

The reason you don't get html tags is because the $ something variable contains the dom fragment rather than the string: the value element retrieves the contents of node (s) in the same way as string (), so it does not serialize the nodes.

Instead, a string representation of the html string would be presented, and you can print it with the value and disable-output-output:

<xsl:variable name="something"><![CDATA[<p>Hi there</p><p>How are you today?</p>]]></xsl:variable>

(. https://msdn.microsoft.com/en-us/library/ms256181(v=vs.110).aspx " , string()" )

+2

All Articles