xsl-list
[Top] [All Lists]

RE: need a variable path in the template-match attribut

2002-11-26 07:07:44

I need an XSLT which copies all nodes to a new XML, but one 
tag needs to be
changed. This should be done with a variable because I want 
to use it in
Apache Cocoon and want to call the stylesheet with a 
parameter like this:

You need to use a choose/when in your indentity transform:

<xsl:template match="@*|node()">
  <xsl:choose>
    <xsl:when test="local-name() = $param">
      <myelement>
        <xsl:apply-templates select="@*|node()"/>
      </myelement>
    </xsl:when>
    <xsl:otherwise>
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

cheers
andrew

-----Original Message-----
From: inchi2000(_at_)gmx(_dot_)de [mailto:inchi2000(_at_)gmx(_dot_)de]
Sent: 26 November 2002 13:48
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] need a variable path in the template-match attribut


Hello!

I need an XSLT which copies all nodes to a new XML, but one 
tag needs to be
changed. This should be done with a variable because I want 
to use it in
Apache Cocoon and want to call the stylesheet with a 
parameter like this:
http://localhost:8080/cocoon/edit?mypath=//ad/new

<xsl:param name="mypath"/>
<xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
</xsl:template>
<xsl:template match="$mypath">
      <xsl:copy>New Text Here</xsl:copy>
</xsl:template>

I know that I can't use variable-references in the match attribut in
templates. But I think this should be possible in some way ;)
Thanks for your help!
Markus Karsch

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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