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