xsl-list
[Top] [All Lists]

Re: variable matching...

2003-12-08 05:18:33


<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">
<title>
<xsl:apply-templates mode="normalise"/>
</title>
</xsl:template>

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
of

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


etc

-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>