[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] position() test for processing boundaries


Subject: RE: [xsl] position() test for processing boundaries
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 19 Nov 2004 13:47:20 -0000

The test is the same in both cases. The third item in .//* is the <rdg
n="3"> element. The two elements before this are the <q n="1"> element and
the <app n="2"> element, and you have obtained deep copies of these two
elements, just as you requested.

However, this isn't going to help with your problem. Doing xsl:copy-of gives
you a deep copy of all the selected nodes, and therefore xsl:copy-of
select=".//*" is going to contain many duplicated nodes: each element will
be copied once its own right, and once as a side-effect of copying its
parent, once when copying its grandparent, and so on.

This kind of problem becomes much easier with the << and >> operators in
XPath 2.0. Select the first and last nodes you want to process (say A and
B), and then you can process all the required nodes using

select="$A | //*[. >> $A and . << $B] | $B"

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Ron Van den Branden [mailto:ron.vandenbranden@xxxxxxxx]
> Sent: 19 November 2004 13:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] position() test for processing boundaries
>
> Hi all,
>
> This is the first time I write to this list, since I have carefully
> tried to check the archives for an answer to my question. I am
> struggling with finding ways to delimit processing of descendant nodes
> based on start and end positions.
>
> A previous posting
> (http://www.biglist.com/lists/xsl-list/archives/200009/msg00181.html)
> comes close, but leaves me confused about one aspect.
> Basically, it has
> to do with a (seemingly?) difference in the way [position() &gt; ...]
> and [position() &lt; ...] predicates are evaluated.
>
> Given this example document fragment:
>
> <p>
>   <q n="1>
>     <app n="2">
>       <rdg n="3">rdg1</rdg>
>       <rdg n="4">rdg2</rdg>
>       <rdg n="5">rdg3</rdg>
>     </app>
>     [text]
>     <anchor n="6"/>
>     <app n="7">
>       <rdg n="8">rdg1</rdg>
>       <rdg n="9">rdg2</rdg>
>       <rdg n="10">rdg3</rdg>
>     </app>
>   </q>
>   [text]
>   <app n="11">
>     <rdg n="12">rdg1</rdg>
>     <rdg n="13">rdg2</rdg>
>   </app>
>   <anchor n="14"/>
>   <q n="15">
>     <app n="16">
>       <rdg n="17">rdg1</rdg>
>       <rdg n="18">rdg2</rdg>
>       <rdg n="19">rdg3</rdg>
>     </app>
>     [text]
>     <anchor n="20"/>
>     text
>     <app n="21" TEIform="app">
>       <rdg n="22">rdg1</rdg>
>       <rdg n="23">rdg2</rdg>
>     </app>
>     [text]
>     </q>
> </p>
>
> I am trying to find ways for delimiting the processing of
> descendants of
> <p>, so that all and only those elements between a certain start
> position and a certain end position are processed. Experimenting with
> ways to express such constraints, I managed to identify a
> basic problem
> (in my understanding, probably). I found following differences:
>
> (A)
>
> Given following example XSLT fragment triggering processing from START
> position 3:
>
> <xsl:template match="p">
>   <xsl:copy-of select="(.//*)[position() &gt; 3]"/>
> </xsl:template>
>
> This one correctly (or, at least, expectedly) copies all descendant
> nodes of <p>, starting from <rdg n="4"> up to the end.
>
> (B)
>
> However, when I use that same position as END position in following
> fragment:
>
> <xsl:template match="p">
>   <xsl:copy-of select="(.//*)[position() &lt; 3]"/>
> </xsl:template>
>
> All direct children of <p> are returned that occur before the
> 3rd direct
> child:
>
> <q n="1">
>   <app n="2">
>     <rdg n="3">rdg1</rdg>
>     <rdg n="4">rdg2</rdg>
>     <rdg n="5">rdg3</rdg>
>   </app>
>   [text]
>   <anchor n="6"/>
>   <app n="7">
>     <rdg n="8">rdg1</rdg>
>     <rdg n="9">rdg2</rdg>
>     <rdg n="10">rdg3</rdg>
>   </app>
> </q>
> <app n="2">
>   <rdg n="3">rdg1</rdg>
>   <rdg n="4">rdg2</rdg>
>   <rdg n="5">rdg3</rdg>
> </app>
>
> This seems to suggest that the position test in case (A) is applied at
> the level of the deepest descendant, while in case (B) at the level of
> the first generation of descendants.
>
> Could anyone explain what makes the difference? Any
> suggestions for the
> right way to delimit processing of descendant nodes up to a certain
> position (in this example only the nodes appearing before
> <rdg n="3">)?
>
> Many thanks in advance!
>
> Ron
>
> --
> Ron Van den Branden
> Wetenschappelijk attachi
> Centrum voor Teksteditie en Bronnenstudie (CTB)
> Koninklijke Academie voor Nederlandse Taal- en Letterkunde (KANTL)
> Koningstraat 18 / b-9000 Gent / Belgium
> e-mail : ron.vandenbranden@xxxxxxxx
> http://www.kantl.be/ctb/staff/ron.htm


Current Thread
Keywords