Subject: RE: [xsl] improve algorithm? From: "bryan" <bry@xxxxxxxxxx> Date: Fri, 21 Jun 2002 12:38:21 +0200 |
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 > 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 > 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 > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] improve algorithm?, bryan | Thread | Re: [xsl] improve algorithm?, Wendell Piez |
Re: [xsl] xsl:copy producing ugly o, David Carlisle | Date | AW: [xsl] count string-length witho, "Braumüller, Hans" |
Month |