Re: [xsl] variable matching...

Subject: Re: [xsl] variable matching...
From: James Cummings <James.Cummings@xxxxxxxxxxxxxx>
Date: Mon, 8 Dec 2003 12:49:04 +0000 (GMT)
On Mon, 8 Dec 2003, David Carlisle wrote:

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

Yup, that is what I thought (well, that it wouldn't/shouldn't work) so why
I asked. ;-) But always good to know why it doesn't work. Thanks.
> 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.
Yup, This has been suggested, and sounds good, unless I'm assuming
I have two elements with different names that I want to normalize to
a single one.  (or does <xsl:variable
name="stage">sd|stageDir</xsl:variable> work? )

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

Well this is sort of what I'm doing.  The original files aren't
xml but cocoa. A perl regular expression changes the cocoa to
an (often) well-formed document of empty elements. so:

<Q Someone> This is a speech
<Q value="Someone" /> This is a speech

This is then changed to a TEI'ish name form of:

<sp speaker="Someone"/> This is a speech

It is at this stage that I want to normalize everything to the
same names.  Because the next stylesheet fills out the xml
(based on suggestions here) and since that is the more
complicated one I want to change it less. This leaves:
<l>This is a speech</l>

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

I'm not sure I understand this.  So make a short stylesheet
which moves things like <Q /> to be <sp /> (in example above)
but don't I need to change that each time?

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

They aren't reliably that identical. (I wish!)


Dr James Cummings, Oxford Text Archive, James.Cummings@xxxxxxxxxxxxxx

 XSL-List info and archive:

Current Thread