[xsl] rephrased: passing parameters to generic templates

Subject: [xsl] rephrased: passing parameters to generic templates
From: Robert Frank <robert.frank@xxxxxxxxx>
Date: Wed, 12 Apr 2006 08:41:37 +0200
Hi,

I noticed I didn't phrase my problem carefully enough (and the example
wasn't correct either - thank's David) - probably too late at night:

I want to convert only certain (html) nodes using a generic template,
but have to pass a parameter to these templates. As the nodes may be
nested within othernodes, I am using the generic copy 'function'

<xsl:template match="@*|node()|text()" priority="-1">
   <xsl:param name="path" select="'zz'"/>
   <xsl:copy>
     <xsl:apply-templates select="@*|node()|text()">
       <xsl:with-param name="path" select="$path"/>
     </xsl:apply-templates>
   </xsl:copy>
</xsl:template>

The more specific template is:

<xsl:template match="/content">
   <test>
     <xsl:apply-templates select="para">
       <xsl:with_param name="path" select="docBase"/>
     </xsl:apply-templates>
   </test>
</xsl:template>

and the element I want to change:

<xsl:template match="a/@href">
   <xsl:param name="path" select="'xx'"/>
   <xsl:attribute name="href"><xsl:value-of select="$path"/>
      <xsl:value-of select="."/></xsl:attribute>
</xsl:template>

A sample xml file could be:
<content>
   <para>
     <docBase>full_path_to_some_directory</docBase>
     This is a test <b>text</b> which should be copied 1:1.
     <a href=3D"local_ref">A reference</a>
     <center><a href=3D"local_ref">A nested reference</a></center>
   </para>
   <para>
     <docBase>next_full_path_to_some_directory</docBase>
     This is a test <b>text</b> which should be copied 1:1.
     <a href=3D"local_ref">A reference</a>
     <center><a href=3D"local_ref">A nested reference</a></center>
   </para>
</content>

I want to use the <docBase> in every <para> to modify the href
of each anhor element.
How can I propagate the parameter's value in the more specific
template into the generic template? The only parameter that is
propagated is the one in the generic template, so all references have
a value of zz...

Thanks in advance, Robert

Departement Informatik   FGB   tel   +41 (0)61 267 14 66
Universitdt Basel                          fax. +41 (0)61 267 14 61
Robert Frank
Klingelbergstrasse 50                 Robert.Frank@xxxxxxxxx
CH-4056 Basel
Switzerland                                   http://
www.informatik.unibas.ch/personen/frank_r.html

Current Thread