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

When/How to use templates, and when to use if/choose

Subject: When/How to use templates, and when to use if/choose
From: "Ian Jolly" <Ian.Jolly@xxxxxxxxxxxxx>
Date: Tue, 19 Jun 2007 22:56:53 +0100
 When/How to use templates
Hello,
I'm relatively new to XSLT programming but have quite a background in Visual Basic. I've been writing some XSLT that works perfectly well, but I believe it not to be of a high standard, but I struggle to see the reasons why. Using templates sometimes seems to be more of a pain than not!


For example:

<xsl:template match="doc:Para">
<p>
<xsl:choose>
<xsl:when test="ancestor::doc:Body">
<xsl:number count="doc:Para" from="doc:Body" level="any"/>
<xsl:text>. </xsl:text>
<xsl:call-template name="prefix"/>
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="ancestor::doc:appendix">
<xsl:element name="font" use-attribute-sets="attSetAppendixBody">
<xsl:call-template name="prefix"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="prefix"/>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</p>
</xsl:template>


should it seems, not use the <xsl:choose>, but what benefit does this give?

Also,

<xsl:template match="doc:title">
<xsl:choose>
<xsl:when test="parent::doc:Table">
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="ancestor::doc:Summary">
<xsl:choose>
<xsl:when test="../../../../doc:Section">
<xsl:choose>
<xsl:when test="../../../../../../../doc:Section">
<p>
<xsl:element name="font" use-attribute-sets="level3attrtitle>
<xsl:apply-templates/>
</
</p>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:element name="font" use-attribute-sets="level2attrtitle>
<xsl:apply-templates/>
</
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:element name="font" use-attribute-sets="level1attrtitle>
<xsl:apply-templates/>
</
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="../../../../doc:Section">
<xsl:choose>
<xsl:when test="../../../../../../../doc:Section">
<p>
<xsl:element name="font" use-attribute-sets="level3attrtitle>
<xsl:apply-templates/>
</
</p>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:element name="font" use-attribute-sets="level2attrtitle>
<xsl:apply-templates/>
</
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:element name="font" use-attribute-sets="level1attrtitle>
<xsl:apply-templates/>
</
</p>
</xsl:otherwise>
</xsl:choose>


etc
etc

So the question is essentially - this code doesn't use templates as much as it should (right?), but what are the benefits of using templates in what to a novice seems a gratuitous way?

Thanks,

Ian

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.