xsl-list
[Top] [All Lists]

Re: [xsl] Using node-set variables in predicates (another node comparison question)

2022-01-01 04:03:58
Use (. intersect X). It may not be intuitive, but it does exactly what you 
want, and it becomes intuitive once you've done it a few times.

Michael Kay
Saxonica

On 1 Jan 2022, at 06:00, Chris Papademetrious 
christopher(_dot_)papademetrious(_at_)synopsys(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi everyone, and happy new year's!
 
Let's say I have a variable that contains a set of nodes:
 
<xsl:variable name="nodes" select="//(foo|bar|baz)"/>
 
In XPath 3.0, I can apply a template directly to this node-set variable (very 
cool!):
 
<xsl:template match="$nodes">
 
However, what's the best way to use this node-set variable as a predicate 
filter? For example, let's say I wanted to select every preceding sibling 
node directly before each node in the variable:
 
<xsl:template match="preceding-sibling::node()[1][. intersect $nodes]">
 
The "interesect" operator works, but it's not intuitive. Is there a simple 
Boolean operator that indicates whether a given node exists in a set of 
nodes? ([. = $nodes] compares text evaluations of the nodes, not the nodes 
themselves.)
 
I hope the answer is not obvious, because I spent longer than I'd like to 
admit trying to figure this out.  :)
 
- Chris
 
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by 
email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>