Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: multipass processing in XSLT 2.0

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 7/7/2009 1:54:00 PM
Larry Sulky wrote:
> Hi. Suppose I want to turn this:
> 
> <indoc>
> <heading>Aaaa aaaa</heading>
> <p y="34" x="22">Iiii iiii.</p>
> <p y="11" x="56">Jjjj jjjj.</p>
> <p y="93" x="70">Kkkk kkkk.</p>
> <z>Ssss ssss.</z>
> </indoc>
> 
> into this:
> 
> <OUTDOC>
> <HEADER A="70" B="93">Aaaa aaaa</HEADER>
> <ZED>Ssss ssss.</ZED>
> <PARA>Iiii iiii.</PARA>
> <PARA>Jjjj jjjj.</PARA>
> <PARA>Kkkk kkkk.</PARA>
> </OUTDOC>
> 
> I've got a mix of elements and attributes, changing places and owners.
> Also need to pick up an attribute value on the last <p> element and
> use it up at the top of the output stream. But I'm finding it
> difficult to find examples of XSLT 2.0 multipass processing, only
> assurances that it's much easier than in 1.0. Can anyone here do a
> quick 2.0 transform that I could then use as a model for this kind of
> task generally? I would be very appreciative. Thanks --

Why do you think you need multiple passes? It can be easily solved with

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="2.0">

   <xsl:output method="xml" indent="yes"/>
   <xsl:strip-space elements="*"/>

   <xsl:template match="indoc">
     <OUTDOC>
       <xsl:apply-templates select="heading, z, p"/>
     </OUTDOC>
   </xsl:template>

   <xsl:template match="heading">
     <HEADER A="{following-sibling::p[last()]/@x}" 
B="{following-sibling::p[last()]/@y}">
       <xsl:apply-templates/>
     </HEADER>
   </xsl:template>

   <xsl:template match="z">
     <ZED>
       <xsl:apply-templates/>
     </ZED>
   </xsl:template>

   <xsl:template match="p">
     <PARA>
       <xsl:apply-templates/>
     </PARA>
   </xsl:template>

</xsl:stylesheet>


As for multiple passes in XSLT 2.0, if you want to do that in one 
stylesheet then process something into a variable and then process the 
nodes in that variable e.g.

   <xsl:template match="foo">
     <xsl:variable name="temp-result">
       <bar>
         <xsl:apply-templates/>
       </bar>
     </xsl:variable>
     <xsl:apply-templates select="$temp-result/bar"/>
   </xsl:template>

   <xsl:template match="bar">
     ...
   </xsl:template>


-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


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