|
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 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: n squared behavior with XT for , Sebastian Rahtz | Thread | Re: n squared behavior with XT for , David Carlisle |
| Problem interpreting XSLT spec..., Larry Fitzpatrick | Date | Re: n squared behavior with XT for , David Carlisle |
| Month |