给定
<xsl:variable name="datePrecision" as="element()*">
<p>Year</p>
<p>Month</p>
<p>Day</p>
<p>Time</p>
<p>Timestamp</p>
</xsl:variable>
表达方式
$datePrecision[5]
如预期的那样,返回一个包含一个值为“Timestamp”的文本节点的节点集。
稍后在模板中,上下文元素具有属性
@precision="5"
我尝试以下表达式,但都返回一个空字符串:
$datePrecision[@precision]
$datePrecision[number(@precision)]
$datePrecision[xs:decimal(@precision)]
但是,以下序列可以满足我的要求
<xsl:variable name="prec" select="number(@precision)"/>
... $datePrecision[$prec] ...
使用 Oxygen/XML 的调试器,我已经走到了即将评估表达式的地步,并在监视窗口中显示以下内容:
Expression Value Nodes/Values Set
-------------------------- --------------- -----------------------
$datePrecision[5] Node Set(1) #text Timestamp
@precision Node Set(1) precision 5
$datePrecision[@precision]
number(@precision) 5
$datePrecision[number(@precision)]
$prec 5
$datePrecision[$prec] Node Set(1) #text Timestamp
显然,我错过了有关如何将属性节点原子化以用于谓词的基本知识,但在文档(Michael Kay 的 XSLT/XPATH 2.0,第 4 版)中找不到任何可以解释这种差异的内容。
有人可以解释为什么会发生这种情况,并指出在 XSLT 2.0 规范或 Michael Kay 的书中描述的地方吗?
(XSLT 处理器是 Saxon-PE 9.2.0.3)