[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: improve algorithm?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|