Re: [xsl] Re: Re: Change of Attribute Value

Subject: Re: [xsl] Re: Re: Change of Attribute Value
From: Ragulf Pickaxe <ragulf.pickaxe@xxxxxxxxx>
Date: Fri, 4 Nov 2005 09:42:19 +0100
Hi Fabrice,

On 11/4/05, Miraodb <miraodb@xxxxxxxxxxx> wrote:
> Hi ragulf,
>
> Thanks for your prompt reply.
> Im' having trouble with your code, it stops at the <xsl:copy-of
> select="@*[not(self::@name)]" /> telling me that it's expecting a node test
> in xsl:copy-of....
>
> doesn't really makes sense to me.

I have looked at one of my projects, and here I use (the equivalent of):
<xsl:copy-of select="@*[not(name()='name')]"/>

With this change, my solution should work.

Alternavtively, as it seems that you only have one other attribute -
description - then you can just add this explicitly, like you do in
your solution. Mine would just make it more genereric (you would be
able to add more attributes to the XML without having to change the
XSLT).

> from what i understand of your solution, it would work fine as long as
> there's only three levels. the problem is that there can be as many level
as
> possible and also that the element node isn't the actual root of the tree.

The solution should work on inifinite depths. This is based on the
node elements only being children of other node elements, not of
elements with different names.

Here is the changed solution, based on your XSLT solution as well:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes" />

<xsl:template match="/">
  <xsl:apply-templates select="node"/>
</xsl:template>

<xsl:template match="node">
  <xsl:copy>
    <xsl:attribute
name="name"><xsl:value-of
select="concat((ancestor::node)[2]/@name,@name)"/></xsl:attribute>
    <xsl:copy-of select="@*[not(name()='name')]"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*[not(self::node)]">
  <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

Regards,
Ragulf Pickaxe :-)

Current Thread