Re: [xsl] XSL - avoiding code duplication

Subject: Re: [xsl] XSL - avoiding code duplication
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 26 May 2003 13:14:17 -0400

Try this:

<xsl:template match="commonref" mode="quux">
  <xsl:variable name="attribute">
    <xsl:call-template name="setattribute">
      <xsl:with-param name="node" select="."/>

The rest, you can probably work out.

Note that strictly speaking you don't need to pass the "node" parameter in or even have the parameter (since the current node of the called template is the same as when it's called); although to have it certainly has its advantages, and can be a very good idea (it makes the template more versatile, etc.).


At 10:07 AM 5/26/2003, you wrote:
I'm trying to cut down on the duplication of XML and XSL in my

...I'm not very fond of this kind of
cut-and-paste development so I tried to write a call-template function
to manage these variables, however, if I do that the scope of the
variables doesn't reach my mode function.  For example:
<xsl:template match="commonref" mode="quux">
   <xsl:call-template name="set-vars">
       <xsl:with-param name="node" select="."/>
   <xsl:value-of select="$attribute"/>
<xsl:template name="set-vars">
  <xsl:param name="node/>
  <xsl:variable name="attribute">
         <xsl:when test="node/@attribute">
            <xsl:value-of select="node/@attribute"/>
            <xsl:value-of select="id(node/@idref)/@attribute"/>
Does not work and gives an error that the variable is out of scope.
Sensible.  But my question is how to I compartmentalize this code so I
don't have to cut-and-paste it all over the place (btw there are about
5 variables I need to do this with each time -- so the c-n-p is a lot
more than it seems here).

Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

XSL-List info and archive:

___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_ "Thus I make my own use of the telegraph, without consulting the directors, like the sparrows, which I perceive use it extensively for a perch." -- Thoreau

XSL-List info and archive:

Current Thread