xsl-list
[Top] [All Lists]

[xsl] changing only one attribute of element copy

2007-07-04 10:39:58
Hello,

It would be nice if someone could tell me the easiest way of changing just one (and keeping the other) attributes of an copied element.

I am using the following templates to copy elements from a source class to a target class:

<xsl:template match="node() | @*" mode="transform">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" mode="transform"/>
  </xsl:copy>
</xsl:template>
        
<xsl:template match="//class[(_at_)name=$TargetCName]" mode="transform">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:copy-of select="//class[(_at_)name=$SrcCName]/field">
    <xsl:apply-templates mode="transform"/>
  </xsl:copy>
</xsl:template>

Inside "class" are elements like
<field id="31" class="3" type="type(basic,int,0)" name="publ_int_j" init="null"/>
which are going to be copied.

What, if I want to change the "id" of the copied element? (Suppose, I don't know that the element name is "field") Do I have to create a completely new element using <xsl:element> and to write down every single attribute explicitely using <xsl:attribute>? Or is there a possibility to copy the old attributes und to create just one new attribute? My problem is, that <xsl:copy-of> doesn't allow <xsl:attribute> inside and <xsl:copy> which allows it doesn't allow a "select" inside...

Regards,
Garvin

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