[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: what does this statement mean?

Subject: RE: what does this statement mean?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 10 Mar 2005 10:58:13 -0000
select 1 from
To try and answer the original question, the "normal" way of processing a
tree in XSLT is that the template rule for each node processes that node,
and calls <apply-templates/> to process all its children, handling each one
using the template rules that matches that node.

This works fine in most cases. But sometimes you need finer control. The
code in this stylesheet (as corrected) is walking the tree more carefully:
from a SubConcepts node it invokes apply-templates to process the first
child (that's what *[1] means), and from that child it processes the next
sibling (using following-sibling::*[1]). This allows you to do things like
stopping at the first child that satisfies a particular condition.

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

> -----Original Message-----
> From: Jarno.Elovirta@xxxxxxxxx [mailto:Jarno.Elovirta@xxxxxxxxx] 
> Sent: 10 March 2005 10:42
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  what does this statement mean?
> 
> Hi,
> 
> > Im trying to rearrange the order of my XML elements using the 
> > <xsl:copy> 
> > feature of XSLT 2.0. However Im having trouble with one 
> line of code 
> > which causes my processor to run into an infinite loop.
> > 
> > Could someone please let me know what this particular 
> > <xsl:apply-templates select="*[1]" mode="walker"/> means and what 
> > exactly its trying to do (this was a piece of code that was 
> > suggested by 
> > someone from this list).
> 
> Might have been me, I use the "walker" mode name for that 
> sort of grouping. Basically it's a grouping method that walks 
> through a flat list of elements and the "walker" mode 
> templates decide whether to stop the walking or continue.
>  
> > The full code is shown below :
> > ----------------------------
> > <xsl:template match="/">
> >     <Top>
> >         <xsl:apply-templates select="Top/SubConcepts"/>
> >     </Top>
> > </xsl:template>
> > 
> > <xsl:template match="SubConcepts">
> >     <xsl:copy>
> >       <xsl:apply-templates select="@*"/>
> >       <xsl:for-each select="descendant::SubConcept">
> >         <xsl:copy>
> >           <xsl:apply-templates select="@*"/>
> >           <xsl:apply-templates select="*[1]" mode="walker"/>  
> >           
> >     <!--problem with this line of code-->
> >         </xsl:copy>
> >       </xsl:for-each>
> >     </xsl:copy>
> > </xsl:template>
> > 
> > <xsl:template match="Value | ChildConcept" mode="walker">
> > <!-- problems during execution-->
> >     <xsl:apply-templates select="."/>
> >     <xsl:apply-templates select="following-sibling::*" 
> mode="walker"/>
> 
> This should be 
> 
>   <xsl:apply-templates select="following-sibling::*[1]" 
> mode="walker"/>
> 
> i.e. continue to the next sibling, not to all of them.
> 
> > </xsl:template>
> > 
> > <xsl:template match="*" mode="walker">                        
> >          
> >             <!-- problems during execution-->
> >     <xsl:apply-templates select="following-sibling::*" 
> mode="walker"/>
> 
> Same here, it should be
> 
>   <xsl:apply-templates select="following-sibling::*[1]" 
> mode="walker"/>
> 
> Cheers,
> 
> Jarno - Neuroticfish: Skin (Binary 2002)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.