Re: [xsl] variable matching...

Subject: Re: [xsl] variable matching...
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 8 Dec 2003 12:18:33 GMT

<xsl:template match="$stage">

Your stage variable contains a result tree fragment (or in xslt2 a node set
consisting of a single document node which has a text node child with
value "stagedir") neither of these is an Xpath pattern, so neither can be
used in a match attribute.

In XSLT 2 however you could do

<xsl:template match="*[name()=$stage]"

as the annoying restriction of not allowing variables in match patterns
is planned to be dropped.

An alternative approach of course, is rather than try to paramaterise
your tempates so they work for all inputs, do a two pass system that
normalises the input.

ie have a main stylesheet that does

<xsl:template match="title">....

then to customise for your second form, in stead of doing this:
<xsl:variable name="stage">stagedir</xsl:variable>

do this

<xsl:template mode="normalise" match="t">
<xsl:apply-templates mode="normalise"/>

This is more flexible as it can cope with differences in structure that
are slightly greater than just element renaming.

If on the other hand the structures are really identical you might not
need names at all eg your two examples could be handles using patterns

match="body/*[1]"                   (t or title)
match="body/*[position() &gt; 1]"   (A or Act)
match="body/*/*"                    (scn or scene)



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

 XSL-List info and archive:

Current Thread