[英]Why <xsl:value-of select="1"/> returns 1?
I'm transforming XML to HTML using a XSLT Stylesheet.我正在使用 XSLT 样式表将 XML 转换为 HTML。 The tansformation engine is provided by Apache Xalan (Version 2.7.0).转换引擎由Apache Xalan (版本 2.7.0)提供。 A Sax Parser is configured to be used. Sax Parser 被配置为使用。
If如果
<xsl:value-of select="1"/>
is used to transform用于变换
<element>
<hello>Hello World</hello>
</element>
Output输出
1 1
According to https://www.w3schools.com/xml/xsl_value_of.asp the xsl:value-of-Tag extracts the value of a selected node based on the given XPath Expression.根据https://www.w3schools.com/xml/xsl_value_of.asp,xsl:value-of-Tag根据给定的 XPath 表达式提取选定节点的值。
The xsl:value-of
instruction returns the result of evaluating the expression contained in its select
attribute (after converting the result to a string). xsl:value-of
指令返回评估其select
属性中包含的表达式的结果(将结果转换为字符串之后)。
An XPath expression can contain numbers, string literals, references to nodes or variables, function calls and operators. XPath表达式可以包含数字,字符串文字,对节点或变量的引用,函数调用和运算符。 The expression 1
is evaluated as the number 1. There can be no node whose name is 1
(an element name cannot start with a digit). 表达式1
的计算结果为数字1。不能有名称为1
节点(元素名称不能以数字开头)。
By using the code通过使用代码
<xsl:value-of select="1"\/><\/code>
you're essentially telling it to return the literal value "1".您实际上是在告诉它返回文字值“1”。
To retrieve the value within the element it would be more like the following:要检索元素中的值,它更像是以下内容:
<xsl:value-of select="hello"\/><\/code>
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.