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>
Any idea, pls share.
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 thegenerate-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.And
current()
gives you the current "top-level" context node - outside a predicatecurrent()
is the same as.
, but inside a predicate expression.
refers to the node the predicate is testing whereascurrent()
still refers to the "outer.
".Now in your example
the outer context node is an
item
element (the one that the outerfor-each
is currently looking at). So starting from thatitem
the expression will select:in other words, all the sibling elements between this
<item lcn="005417714">
(exclusive) and the next<item lcn="anything-non-empty">
(inclusive).Taking an example from the linked question:
if the current context node is the
item
withid="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