简体   繁体   English

"<i>Why<\/i>为什么<\/b><xsl:value-of select="1"\/><i>returns 1?<\/i>返回 1?<\/b>"

[英]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 表达式提取选定节点的值。

  • Why is the output 1 though there is no node 1?为什么没有节点 1 却输出 1?
  • How does this simple transformation work?这个简单的转换是如何工作的?

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.

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