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

improve algorithm?

Subject: improve algorithm?
From: "bryan" <bry@xxxxxxxxxx>
Date: Fri, 21 Jun 2002 11:35:22 +0200
improve algorithm

Hey all,
 I'm doing some stuff with the OpenOffice xml output by Writer, because
it's a pretty flat format and likely to have all sorts of different
structure I want to match whatever gets done but as soon as a Headline
style gets made I want to grab succeeding content and move it under my
own headline format until I get to another Headline and so forth. Anyhow
my code works, at least in the test cases I've run so far, and it
doesn't give me any problems now but I worry  I've probably thought
things out poorly in some ways, and am now too close to the code to
properly evaluate, if you see something that could be improved in the
following templates please suggest the improvement.


<xsl:template match="office:body">
<xsl:apply-templates select="child::*[1]" mode="first"/>
</xsl:template> 


<xsl:template match="*" mode="first">
<xsl:choose>
<xsl:when test="name() = 'text:h'">
<xsl:apply-templates select="self::text:h" mode="assemble"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="self::*"/>
<xsl:apply-templates select="following-sibling::*[1]" mode="first"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>



<xsl:template match="*" mode="assemble">
<xsl:param name="lev" select="@text:level"/>
<xsl:param name="level">
<xsl:choose>
<xsl:when test="$lev &gt; 3">3
</xsl:when> 
<xsl:otherwise><xsl:value-of
select="$lev"/></xsl:otherwise></xsl:choose>
</xsl:param>
<xsl:param name="seq"><xsl:number level="any"/></xsl:param>


<xsl:if test="local-name() ='h'">
<xsl:if test="$lev = '1'">
<xsl:element name="{concat('section',$level)}"><xsl:attribute name="id">
	<xsl:value-of select="concat('s',$seq)"/></xsl:attribute>
	<xsl:element name="{concat('title',$seq)}"><xsl:apply-templates
select="self::*"/></xsl:element><xsl:apply-templates
select="following-sibling::*[1][local-name()!='h']"
mode="assemble"/><xsl:apply-templates
select="following-sibling::text:h[1][@text:level != '1']"
mode="assemble"/></xsl:element><xsl:apply-templates
select="following-sibling::text:h[@text:level = '1'][1]"
mode="assemble"/>
	</xsl:if>
	<xsl:if test="$lev = 2 or $lev &gt; 2">
<xsl:element name="{concat('section',$level)}"><xsl:attribute name="id">
	<xsl:value-of select="concat('s',$seq)"/></xsl:attribute>
	<xsl:element name="{concat('title',$seq)}"><xsl:apply-templates
select="self::*"/></xsl:element><xsl:apply-templates
select="following-sibling::*[1][local-name() !='h']" mode="assemble"/>
</xsl:element>
	<xsl:apply-templates
select="following-sibling::text:h[1][@text:level !='1']"
mode="assemble"/>
	</xsl:if> 


</xsl:if> 


<xsl:if test="local-name() != 'h'">
<xsl:apply-templates select="self::*"/>
<xsl:apply-templates select="following-sibling::*[1][local-name()
!='h']" mode="assemble"/>
</xsl:if> 

</xsl:template> 



 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.