XSLT 了解 generate-id 的工作方式 [英] XSLT understand about the generate-id working way

查看:25
本文介绍了XSLT 了解 generate-id 的工作方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进一步到此链接 xslt 返回以下兄弟姐妹的选择我只是想知道,这里 generate-id 的目的是什么,以及它在这个匹配协议中的意义.

Further to this link xslt return selection of following siblings I Just to want to know, here, what is purpose of this generate-id and how it is making sense in this matching protocol.

<xsl:for-each select="/items/item[@lcn='005417714']">
  <xsl:for-each select="following-sibling::*[generate-id(preceding-sibling::item[@lcn != ''][1]) = generate-id(current())]">
  </xsl:for-each>
</xsl:for-each>

任何想法,请分享.

推荐答案

generate-id 的规范是它总是为同一个节点返回相同的 ID,不同节点返回不同的 ID.因此,比较两个节点的 generate-id 值是检查它们是否是同一个节点的方式,而不仅仅是两个碰巧具有相同值的节点.

The specification of generate-id is that it will always return the same ID for the same node and different IDs for different nodes. Thus, comparing the generate-id values of two nodes is the way you check whether they are the same node as opposed to just two nodes that happen to have the same value.

并且 current() 为您提供当前的顶级"上下文节点 - 在谓词之外 current() 相同.,但是在谓词表达式中 . 指的是谓词正在测试的节点,而 current() 仍然指的是外部 .".

And current() gives you the current "top-level" context node - outside a predicate current() is the same as ., but inside a predicate expression . refers to the node the predicate is testing whereas current() still refers to the "outer .".

现在在你的例子中

following-sibling::*[generate-id(preceding-sibling::item[@lcn != ''][1])
                      = generate-id(current())]

外部上下文节点是一个 item 元素(外部 for-each 当前正在查看的元素).所以从那个 item 开始,表达式将选择:

the outer context node is an item element (the one that the outer for-each is currently looking at). So starting from that item the expression will select:

following-sibling::*                      --- all the following sibling elements
 [                                        --- such that
  generate-id(                            --- the identity of
   preceding-sibling::item[@lcn != ''][1] --- that element's nearest preceding
                                              item with a non-empty lcn attribute
  )
  =                                       --- is the same as
  generate-id(current())                  --- the identity of the item we started
                                              with
 ]

换句话说,这个 (独占)和下一个 (含).

in other words, all the sibling elements between this <item lcn="005417714"> (exclusive) and the next <item lcn="anything-non-empty"> (inclusive).

以链接问题为例:

<item id="00100687" label="A/161i r" lcn="005417714" notes="A/161-182"/>
<item id="00100688" label="A/161i v" lcn="" notes=""/>
<item id="00100819" label="A/182ii v" lcn="" notes=""/>
<item id="00100820" label="A/182iii r" lcn="" notes=""/>
<item id="00100821" label="A/182iii v" lcn="" notes=""/>
<item id="00100822" label="A/183i r" lcn="005417715" notes="A/183-218"/>
<item id="00100823" label="A/183i v" lcn="" notes=""/>
<item id="00100975" label="A/216iii r" lcn="" notes=""/>

如果当前上下文节点是带有 id="00100687"item,那么该选择将拉出项目 00100688、00100819、00100820、00100821 和 00100822.如果你想要排除 00100822 你必须添加另一个谓词

if the current context node is the item with id="00100687" then that select would pull out items 00100688, 00100819, 00100820, 00100821 and 00100822. If you wanted to exclude 00100822 you'd have to add another predicate

following-sibling::*[@lcn = '']
                    [generate-id(preceding-sibling::item[@lcn != ''][1])
                      = generate-id(current())]

这篇关于XSLT 了解 generate-id 的工作方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆