我是 xslt 的新手,一些基本问题困扰着我。其中之一是:
当我使用 xslt 2.0 处理器时,version="1.0"
在我的样式表中意味着什么。即使我(在我的样式表中)有非 1.0 函数,尽管我已明确将样式表版本声明为 1.0,但它仍会被处理。
对我来说,似乎 version
属性除了提供信息之外没有其他属性。
它不配置处理器。那么它有什么用呢?
另一个问题是:
(xslt处理器)、(xslt样式表)和(xpath)的版本之间有什么关系吗?
提前谢谢您。
最佳答案
参见http://www.w3.org/TR/xslt20/#backwards ,如果 XSLT 2.0 处理器支持,则 version="1.0"
启用向后兼容处理,一个主要区别是 <xsl:value-of select="foo"/>
输出一个文本节点,其中包含第一个选定的字符串值 foo
元素同时 version="2.0"
将输出所有选定的 foo
的值元素。
例如,请参阅 http://xsltransform.net/6r5Gh2R ,它处理输入
<?xml version="1.0" encoding="UTF-8"?>
<root>
<items>
<item>foo</item>
<item>bar</item>
</items>
</root>
使用样式表
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<result>
<result version="2.0">
<xsl:apply-templates/>
</result>
<result version="1.0">
<xsl:apply-templates mode="backwards"/>
</result>
</result>
</xsl:template>
<xsl:template match="@*|node()" mode="#all">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="items">
<xsl:copy>
<xsl:value-of select="item"/>
</xsl:copy>
</xsl:template>
<xsl:template match="items" version="1.0" mode="backwards">
<xsl:copy>
<xsl:value-of select="item"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
其中有两个 template match="items"
在不同模式下,一个模板使用 version="1.0"
,样式表的结果是
<?xml version="1.0" encoding="UTF-8"?>
<result>
<result version="2.0">
<root>
<items>foo bar</items>
</root>
</result>
<result version="1.0">
<root>
<items>foo</items>
</root>
</result>
</result>
它演示了 value-of select="item"
的区别评估取决于version
.
关于xml - .xsl 声明中版本属性的含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33390939/