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

RE: improve algorithm?

Subject: RE: improve algorithm?
From: "bryan" <bry@xxxxxxxxxx>
Date: Fri, 21 Jun 2002 12:38:21 +0200
mode assemble
Previous version;
Okay just doing my tidying up changed the ifs to choose/when otherwise
where appropriate in assemble mode. This is probably the part that's
bugging me most, I hate if's and choose but I don't think would function
better as templates. 


<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:choose>
<xsl:when test="local-name() ='h'">
<xsl:choose>
	<xsl:when 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:when>
	
	<xsl:otherwise>
	<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:otherwise>
 
</xsl:choose>

</xsl:when> 


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

[<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.