|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Saxon node matching order
2008/11/28 Ed Yau <eyau@xxxxxxxxxxxxxxx>:
> Hi all,
>
> I have a question about how Saxon chooses which node to match next.
>
> I have some XML that looks a bit like this:
>
> <x>
> <y>
> <z>Peter</z>
> </y>
> <z> </z>
> <y>
> <z>Jones</>
> </y>
> </x>
>
> What I'm trying to achieve is the follow:
>
> <x>
> <z>Peter</z>
> <z> </z>
> <z>Jones</>
> </x>
>
> With the code below:
>
> <xsl:template match="x" >
> <xsl:apply-templates select="y|z"/>
> </xsl:template>
>
> <xsl:template match="y">
> <xsl:apply-templates select="z"/>
> </xsl:template>
>
> <xsl:template match="z">
> <xsl:copy-of select="."/>
> </xsl:template>
>
> <xsl:template match="@*|*">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()">
> </xsl:apply-templates>
> </xsl:copy>
> </xsl:template>
>
>
> But annoyingly my code seems to be doing this instead:
>
> <x>
> <z>Peter</z>
> <z>Jones</z>
> <z> </z>
> </x>
>
> It is obviously matching all the <y> tags before the <z> tags.
> Does anyone know of a way around this?
>
Just change:
<xsl:template match="x" >
<xsl:apply-templates select="y|z"/>
</xsl:template>
to:
<xsl:template match="x" >
<xsl:apply-templates/>
</xsl:template>
In the former you are controlling the order of processing by selecting
the nodes to process, in the latter the input controls the order
because you process the nodes in document order.
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








