简体   繁体   English

XSLT value-of仅返回文本

[英]XSLT value-of returns text only

I'm using XSLT to show a node from XML. 我正在使用XSLT从XML显示一个节点。 This node contains a HTML unordered list like this: 此节点包含一个HTML无序列表,如下所示:

<ul><li>one</li><li>two</li></ul>

but <xsl:value-of select="root/node1" disable-output-escaping="yes" /> returns only onetwo 但是<xsl:value-of select="root/node1" disable-output-escaping="yes" />仅返回一个onetwo

I know i need to use disable-output-escaping="yes" But this does nothing. 我知道我需要使用disable-output-escaping="yes"但这没有任何作用。

I want the output to be the same as in the node, like this: <ul><li>one</li><li>two</li></ul> 我希望输出与节点中的输出相同,如下所示: <ul><li>one</li><li>two</li></ul>

我认为您想使用<xsl:copy-of>代替。

xsl:value-of is used to create text nodes by evaluating the string-value of the selected node. xsl:value-of用于通过评估所选节点的字符串值来创建文本节点。

You need to use xsl:copy-of . 您需要使用xsl:copy-of

http://www.w3.org/TR/xslt#value-of http://www.w3.org/TR/xslt#value-of

The xsl:value-of element is instantiated to create a text node in the result tree. 实例化xsl:value-of元素在结果树中创建一个文本节点 The required select attribute is an expression; 必需的select属性是一个表达式; this expression is evaluated and the resulting object is converted to a string as if by a call to the string function. 计算该表达式并将结果对象转换为字符串,就像通过调用string函数一样。 The string specifies the string-value of the created text node. 字符串指定创建的文本节点的字符串值。 If the string is empty, no text node will be created. 如果字符串为空,则不会创建任何文本节点。 The created text node will be merged with any adjacent text nodes. 创建的文本节点将与任何相邻的文本节点合并。

The xsl:copy-of element can be used to copy a node-set over to the result tree without converting it to a string. xsl:copy-of元素可用于将节点集复制到结果树,而无需将其转换为字符串。 See [ 11.3 Using Values of Variables and Parameters with xsl:copy-of ]. 请参见[ 11.3在xsl:copy-of中使用变量和参数的值 ]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM