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

Re: n squared behavior with XT for 'preceding' tests?

Subject: Re: n squared behavior with XT for 'preceding' tests?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Jul 1999 18:24:16 -0400
g squared templates
At 99/07/22 09:30 +0000, Sebastian Rahtz wrote:
>David Carlisle writes:
> > I less wisely did:
>
>thank goodness you don't need any sleep, is all I can say. But I am
>very happy to see the result, even if I am noty sure entirely why it
>works... perhaps we need the Holman Annotation.

:{)}

I can't always take the time to do this, but I always enjoy learning from
David.

The annotated version is below.

I hope this helps.

................ Ken

T:\FTEMP>type test.xml
<math>

<mrow>
<mi>a</mi><mi>b</mi><mi>c</mi><mn>1</mn>
<mi>x</mi><mi>y</mi><mi>z</mi><mn>2</mn>
</mrow>

</math>

T:\FTEMP>type test.xsl
<!--XSL stylesheet by David Carlisle; annotations by G. Ken Holman-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
                default-space="strip"
                indent-result="yes">

                    <!--for everything that isn't special, just copy it-->
<xsl:template match="*" >
<xsl:copy>
     <xsl:apply-templates/>
</xsl:copy>
</xsl:template>
         
       <!--this element needs to be coagulated with following adjacents-->
<xsl:template match="mi">                    
         <!--if this is the first in a run of adjacents, handle the run-->
<xsl:if test="not(from-preceding-siblings(*[position()=1 and  
                                            from-self(mi)]))">
     <xsl:apply-templates mode="grab" select="."/>
</xsl:if>
      <!--otherwise, this isn't the first, so it must have been handled-->
</xsl:template>

  <!--walk along adjacent elements of same name, tracking concatenation-->
<xsl:template mode="grab" match="mi">
<xsl:param-variable name="x" expr="''"/>    <!--first time around empty-->
<xsl:choose>
  <xsl:when test="from-following-siblings(*[position()=1 and 
                                            from-self(mi)])">   
                 <!--there are more where this came from, keep grabbing-->
     <xsl:apply-templates mode="grab" 
                          select="from-following-siblings(*[1])">
       <xsl:param name="x" expr="concat($x,.)"/>      <!--result so far-->
     </xsl:apply-templates>
   </xsl:when>
   <xsl:otherwise>
              <!--we have reached the end of a grouping, put out result-->
     <mi><xsl:value-of select="concat($x,.)"/></mi>
   </xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

T:\FTEMP>call xsl test.xml test.xsl testout.xml
T:\FTEMP>type testout.xml
<math>
<mrow>
<mi>abc</mi>
<mn>1</mn>
<mi>xyz</mi>
<mn>2</mn>
</mrow>
</math>

T:\FTEMP>

--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Publications:   Introduction to XSLT (3rd Edition) ISBN 1-894049-00-4
Next instructor-led training:   MS'99 1999-08-16  MT'99 1999-12-05/06


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.