[xsl] param vs context for passing arguments

Subject: [xsl] param vs context for passing arguments
From: Piotr Dobrogost <pd@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Dec 2009 23:46:18 +0100

This is simple template to replace hyphen with underscore in 'name' attribute of some element;

<xsl:template name="ReplaceHyphenWithUnderscore">
  <xsl:analyze-string select="@name" regex="-">
      <xsl:value-of select="."/>

I'm using it to transform some of 'xsd:element' elements' 'name' attribute like this;

<xsl:template match="xsd:element[<some condition here>]">
  <xsl:call-template name="ReplaceHyphenWithUnderscore"/>

Now, I need to do the same transformation with 'xsd:attribute' elements but to another attribute this time - type. I could add a parameter to ReplaceHyphenWithUnderscore template to let know which attribute it should act upon. But this seems to be not in the spirit of xslt. Shouldn't rather ReplaceHyphenWithUnderscore always act upon context node instead? Then it would be a task of caller to set proper context node before calling the template.

How could I change context node (focus) being inside
<xsl:template match="xsd:element[<some condition here>]">
before calling
<xsl:call-template name="ReplaceHyphenWithUnderscore"/>
and reverting it back after this call so following lines of template would be evaluated in the original context set by 'match' clause?

Regards Piotr Dobrogost

Current Thread