XSLT2: How to reference attributes about the current node in XPath2 predicates

左心房为你撑大大i 提交于 2019-12-05 16:32:51

In XSLT 1.0 you can use the standard function current() which refers to the node that is matched by the current template or the inner-most xsl:for-each:

/potato/stem[@sessionID=current()/@sessionID][scc]/scc/@leafnumber

or by defining a key (at a global level):

<xsl:key name="kPotById" match="stem[scc]" use="@sessionID"/>

and referencing this key:

key('kPotById', @sessionID)/scc/@leafnumber

In XSLT 2.0 / XPath 2.0 you have additional ways to express this (range variables):

for $thisSessionID in @sessionId
 return
    /potato/stem[@sessionID=$thisSessionID][scc]/scc/@leafnumber

Use e.g. current()/@sessionID to access the sessionID attribute of the currently processed node (e.g. the one processed by the for-each in your sample or by an apply-templates with push processing).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!