[xsl] variable matching...

Subject: [xsl] variable matching...
From: James Cummings <James.Cummings@xxxxxxxxxxxxxx>
Date: Mon, 8 Dec 2003 11:40:03 +0000 (GMT)
Hi there,

Let's say I have many different files, all with similar-but-differing
markup all of which I'm converting to the same structure.  In this case,
let's say I'm looking at plays so everything has the same basic
structure (acts, scenes, speeches, lines, stage directions).  Is there
a way of using variables (or parameters) to make transforming the names
easier without continually editing the main templates throughout the
xslt.

file a:
<body>
<title>A test file</title>
<Act><head>Act 1</head>
  <scene>
    <sd>Enter somebody</sd>
     <speech actor="foo">
      <line>This is a line</line>...
     </speech>
  </scene>...
</Act>...
</body>

file b:
<body>
<t>A test file</t>
<A><h1>Act 1</h1>
  <scn>
    <stagedir>Enter somebody</stagedir>
     <lines actor="foo">
      <l>This is a line</l>...
     </lines>
  </scn>...
</A>...
</body>

These have basically the same structure, but with differing element
names.

Is there a way for me to do something like:

<xsl:variable name="title">title</xsl:variable>
<xsl:variable name="act">Act</xsl:variable>
<xsl:variable name="scene">scene</xsl:variable>
<xsl:variable name="stage">sd</xsl:variable>

for the first file and then change the xsl it (or
pass these as parameters instead):

<xsl:variable name="title">t</xsl:variable>
<xsl:variable name="act">A</xsl:variable>
<xsl:variable name="scene">scn</xsl:variable>
<xsl:variable name="stage">stagedir</xsl:variable>

And do something like

<xsl:template match="$stage">
<stage><xsl:apply-templates/></stage>
</xsl:template>

I think this is not allowed, but was wondering if
there was a way (xslt2 acceptable) to do this kind
of thing?  I suppose instead of variables or parameters,
a secondary xml file would be another option.

Obviously I don't want to just do:
<xsl:template match="sd|stagedir">
<stage><xsl:apply-templates/></stage>
</xsl:template>
because sometimes one file will use an element name
that conflicts with another file's use of it.

I'm really looking for an easy way to not have to
customise the main bit of the xslt for each and every
file.

Suggestions?
-James

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

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


Current Thread