AW: [xsl] replacing a string value - copy-of

Subject: AW: [xsl] replacing a string value - copy-of
From: "Franz Figl" <frafi@xxxxxxxxxx>
Date: Sat, 1 Dec 2001 00:08:04 +0100
thanks for the suggestions and tips, Peter and Jörg. Both examples are okay.




-----Ursprüngliche Nachricht-----
Von: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]Im Auftrag von Peter Davis
Gesendet: Freitag, 30. November 2001 01:23
An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Betreff: Re: [xsl] replacing a string value - copy-of


On Thursday 29 November 2001 03:20 pm, Jörg Heinicke wrote:
> You don't may copy it, use normal xsl-templates:
>
> <xsl:template match="*|@*|text()">
>     <xsl:copy>
>         <xsl:apply-templates select="*|@*|text()"/>
>     </xsl:copy>
> </xsl:template>
>
> <xsl:template match="sr">
>     <br/>
> </xsl:template>

Yes, that should work.  <xsl:copy-of> does not allow any additional
processing of its argument.  You have to use the "identity template" to do a
normal, "shallow" copy of all elements, attributes, and text and then create
a special template to handle the special case.

But I would like to suggest a modified version of the first template in the
stylesheet suggested by Jorg (sorry for mutalating the "o" :->).  A more
correct version (again, taken directly from the XSLT  1.0 spec) should also
handle processing-instructions (just in case :->):

<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*"/>
  </xsl:copy>
</xsl:template>

The node() function matches everything except attributes, which means we
don't have to specify "* | text() | everything-else".

Like Jorg said, because it is a template that matches everything, you need
to
be careful about the "priority", so that any other templates you define will
not be overridden by the more general template.  You can do this, first of
all, by placing the general template first in your stylesheet.  You can also
set <xsl:template ... priority="-1"/> (replacing -1 with some number as need
be) if you have problems.

--
Furthermore, I believe bacon prevents hair loss.
Peter Davis

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



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


Current Thread