We can insert HTML tags in an XSL variable

I just want to confirm if we can insert html tags inside xsl variable? Example

<xsl:variable name="htmlContent"> <html> <body> hiiii </body> </html> </xsl:variable> 

if i use

 <xsl:value-of select="$htmlContent"/> 

I want to receive

 <html> <body> hiiii </body> </html> 

Is it possible? I tried

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

Although I do not get the desired result

+6
source share
1 answer

Do not use value-of , which gets the text value of the selected node. Instead, use copy-of , which copies the entire tree (nodes and everything) to the output:

 <xsl:copy-of select="$htmlContent"/> 

Here is a complete example:

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="htmlContent"> <html><body>hiiii</body></html> </xsl:variable> <xsl:template match="/"> <xsl:element name="htmlText"> <xsl:copy-of select="$htmlContent"/> </xsl:element> </xsl:template> </xsl:stylesheet> 

This will always produce xml:

 <htmlText> <html> <body>hiiii</body> </html> </htmlText> 
+10
source

All Articles