Subject: [xsl] improve algorithm? From: "bryan" <bry@xxxxxxxxxx> Date: Fri, 21 Jun 2002 11:35:22 +0200 |
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 > 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 -> |
---|---|---|
AW: [xsl] Re: : Re: AW: Article: An, Braumuller, Hans | Thread | RE: [xsl] improve algorithm?, bryan |
Re: [xsl] count string-length witho, David Carlisle | Date | [xsl] xsl:copy producing ugly outpu, Richard Mitchell |
Month |