can we insert HTML tags in XSL Variable

萝らか妹 提交于 2019-12-04 00:23:16

问题


I just want to confirm whether we can insert html tags inside the xsl variable? example

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

if i use

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

I shoud get

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

Is it possible? i have tried

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

Eventhough i am not getting the desired output


回答1:


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 all) into the output:

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

Here is a full 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 the xml:

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


来源:https://stackoverflow.com/questions/13200567/can-we-insert-html-tags-in-xsl-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!