xsl-list
[Top] [All Lists]

[xsl] passing parameters to generic templates

2006-04-10 14:58:53
Hi,

I'm stuck with the following problem (which is version independent):

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="/">
  <test>
    <xsl:apply-templates select="/content/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>
  <docBase>full_path_to_some_directory</docBase>
  <para>
    This is a test <b>text</b> which should be copied 1:1.
    <a href="local_ref">A reference</a>
    <center><a href="local_ref">A nested reference</a></center>
  </para>
</content>

I want everything between the <para> ... </para> to copied verbose, except for the href of the anchors, which should be prefixed by the value of <docBase>. 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...

Yes, I tried the archives, got 0 responses (as usual, I probably didn't ask the right question ...)

Thanks in advance, Robert

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




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>