Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - multipass processing in XSLT 2.0 >Thread Next - Re: multipass processing in XSLT 2.0 Re: multipass processing in XSLT 2.0To: 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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
