[xsl] using name() to generate a tag dynamically in xsl output

Subject: [xsl] using name() to generate a tag dynamically in xsl output
From: mark bordelon <markcbordelon@xxxxxxxxx>
Date: Fri, 26 Feb 2010 11:05:06 -0800 (PST)
Dear Group,

I have exhasuted the resources and must now turn to the experts.

My problem: I have two similar templates in my xsl file:

<xsl:template match="clause[@s_len&gt;0 and @s_len&lt;5]">
<clause>
	<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
	<xsl:attribute name="text_title"><xsl:value-of select="/*/@title" /></xsl:attribute>
</clause>
</xsl:template>

<xsl:template match="line[@s_len&gt;0 and @s_len&lt;5]">
<line>
	<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
	<xsl:attribute name="text_title"><xsl:value-of select="/*/@title" /></xsl:attribute>
</line>
</xsl:template>

Since they are so similar I would like to combine them into one to gain greater flexibility and ease of maintenance. Something like this, maybe:

<xsl:template match="clause[@s_len&gt;0 and @s_len&lt;5] | line[@s_len&gt;0 and @s_len&lt;5]">

   ...

</xsl:template>

or even better, since both clause and line tag are always the parent of  <word>, something like this is the most flexible and correct:

<xsl:template match="word/..[@s_len&gt;0 and @s_len&lt;5]">

   ...

</xsl:template>

The only problem is that the tag name in this template will be variable. 

My question is then, how can I use name() to generate the context's tag name in that template?

I have tried composing it with <xsl:text>, but that does not work.

Can someone point me in the right direction?

Thanks in advance,

Mark Bordelon
Getty Trust

Current Thread