Re: [xsl] Suggestions to improve my XSL writing style
Subject: Re: [xsl] Suggestions to improve my XSL writing style|
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 28 Jan 2011 09:27:25 +0000
On 28/01/2011 08:20, Jacobus Reyneke wrote:
The usual error of beginners is that they don't use apply-templates
enough and over use for-each and value-of. apply-templates is the heart
and soul of xslt, the more times it's used the merrier.
The XSL I wrote below works, but I'm looking for ways to improve my
coding style. Is this a bad way of writing style sheets? - in
particular the fact that I call "apply-templates" about a million
Also, I could not get the Act numbering to be added in the Scene
title, so I left it in the Act element, where I would have liked a
Scene title like "Act 1, Scene 1" but using position() from within the
scene match gave me strange numbering.
if you just use <xsl:apply-templates/> that means select="node() so
selects all nodes includng he white space text nodes between elements
and so position() probably went up in steps of two. You could use
<xsl:apply-templates select="scene"/> in your act template 9if scenes
are the only child type) then the sequence being processed will just
have scenes and position() will reflect the scene number. but probably
better would be to use xsl:number from="act" count="scene"
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.