Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Positional predicates in pattern matching

From: Josh Canfield <joshcanfield@--------->
To:
Date: 7/2/2004 5:11:00 AM
Take a look at http://www.w3.org/TR/xpath#section-Location-Steps

"The initial node-set is filtered by the first predicate to generate a
new node-set; this new node-set is then filtered using the second
predicate, and so on. The final node-set is the node-set selected by
the location step. The axis affects how the expression in each
predicate is evaluated and so the semantics of a predicate is defined
with respect to an axis. See [2.4 Predicates]."

This clearly lays out how multiple predicates are evaluated, and what
their node-set context is.

Try thinking about it as layers of filters. 

The first predicate [something] returns a node-set containing only
nodes which have a child element named "something". The second
predicate is operating on this new node-set, so [2] returns the second
node in that list.

Consider the following xml:

<nodes>
  <b/>
  <b id="1"><something id="1.1"/></b>
  <b id="2"/>
  <b id="3"><something id="3.1"/></b>
</nodes>

this xsl:
<xsl:copy-of select="/nodes/b[something]"/>

would output 
<b id="1"><something id="1.1"/></b>
<b id="3"><something id="3.1"/></b>

this xsl:
<xsl:copy-of select="/nodes/b[something][2]"/>

would output
<b id="3"><something id="3.1"/></b>


Does that help?
Josh

On Fri, 2 Jul 2004 18:24:48 +0100, Kevin Jones <kjones@xxxxxxxxxxx> wrote:
> 
> I am clearly missing something here or at least not explaining very well.
> 
> If we are talking about a pattern,
> 
> b[2] - match the 'b' which is the second sibling 'b'
> 
> b[something][2] - match the second node that survives the match b[something]
> 
> At least that is what I read the standard & earlier quote as saying although I
> could clearly be wrong on one or both counts. I suspect both of you are
> saying,
> 
> b[something][2] - match the 'b' which is the second sibling 'b' if 'something'
> evaluates to true.
> 
> This is what I understand Saxon to be doing.
> 
> The standard explains how the first predicate evaluation starts but is rather
> silent on the effect on subsequent predicates. The simplest argument for the
> first behaviour is that it is after the first predicate we follow normal
> XPath behaviour.
> 
> Thanks for your replies,
> Kev.
> 
> 
> 
> 
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
> 
>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent