xsl-list
[Top] [All Lists]

Re: Copy element with attributes

2005-11-29 08:52:45

Thanks, you pointed it out to me:

<xsl:template match="body/@text">
<xsl:attribute name="text">#000000</xsl:attribute>
</xsl:template>

<xsl:template match="body">
<xsl:copy>
<xsl:apply-templates select="@*"/><! -- this was failing me -->
Prepend
<xsl:apply-templates/>
Append
</xsl:copy>
</xsl:template>





From: Ragulf Pickaxe <ragulf(_dot_)pickaxe(_at_)gmail(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Copy element with attributes
Date: Tue, 29 Nov 2005 14:25:13 +0100

Hi Diogo,

> The xslt I use:
>
> <xsl:template match="body">
> <xsl:copy>
> Prepend text
> <xsl:apply-templates/>
> Append text
> </xsl:copy>
> </xsl:template>
>
> removes body tag attributes. How can
> I copy the body tag attributes at the
> same time, so I can use something like:
>
> <xsl:template match="body/@text">
> <xsl:attribute name="text">#000000</xsl:attribute>
> </xsl:template>
>
> to change attributes.

I am not sure quite what you want.
If you want to copy the attributes as is, you should do something like:
<xsl:copy>
<xsl:copy-of select="@*"/>
Prepend text
<xsl:apply-templates/>
...

If you want to do something with the attributes, you should perhaps do
something like:
<xsl:copy>
<xsl:apply-templates select="@*"/>
...

Or you can do something like:
<xsl:copy>
<xsl:for-each select="@*">
<xsl:attribute name="name()"><!-- Do something here --></xsl:attribute>
</xsl:for-each>
Prepend text
...

I do not know if this is what you want.

Regards,
Ragulf Pickaxe :-)

--~------------------------------------------------------------------
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>
--~--


_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


--~------------------------------------------------------------------
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>