Storing html tags within an xsl variable

可紊 提交于 2019-12-31 04:40:44

问题


Sorry if this is a dumb question, but it is possible to store, and retrieve, a HTML snippet within an 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 just when I try, it seems to strip the HTML tags out. Thanks.


回答1:


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




回答2:


I'll add some explanation of what's happening :)

The reason you're not getting the html tags is that the $something variable contains a dom fragment, not a string: the value-of element extracts the content of the node(s) the same way as the string() function does, so does not serialize the nodes.

This would provide, instead, a string representation of the html string you have and you can then print it out with value-of and disable-output-escaping:

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

(see https://msdn.microsoft.com/en-us/library/ms256181(v=vs.110).aspx "The results are converted to a string, as by a call to the string() function")



来源:https://stackoverflow.com/questions/9907302/storing-html-tags-within-an-xsl-variable

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