Re: [xsl] How can one get the name of a template or function?

Subject: Re: [xsl] How can one get the name of a template or function?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 11 Feb 2009 16:37:09 GMT
> BTW, I realize that I could do:
> 
> <xsl:template name="foo" as="item()*">
>   <xsl:variable name="my-name" as="xsd:string" select="string('foo')"
> />

or simpler, but equivalent.

<xsl:template name="foo" as="item()*">
  <xsl:variable name="my-name" select="'foo'" />

That's what I'd do.

> but I would prefer not to do that since when the name attribute
> changes, I need to keep the variable in sync too.

It is easy to automate the adding of such a variable, either just
running a regexp-replace over the stylesheet in emacs etc or using xslt,
eg

don't directly execvute the stylesheet you write, execute the output of
the result of transforming the stylesheet with an identity template plus

<xsl:template match="*:template[@name]/*:variable[@name='my-name']"/>

to throw away the old names, and


<xsl:template match="*:template[@name]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:element name="xsl:variable">
<xsl:attribute name="name" select="'my-name'"/>
<xsl:attribute name="select">'<xsl:value-of
select="@name"/>'</xsl:attribute>
<xsl:copy-of select="node()"/>
</xsl:copy>
<xsl:template>

to add new name variables.

David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread