p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   translate element name to element name (http://p2p.wrox.com/showthread.php?t=47362)

lexzeus September 4th, 2006 08:46 AM

translate element name to element name
 
Hi,

How to translate:

<aName att1="1" att2="2" att3="3">

to

<differentName att1="1" att2="2" att3="3">

?

Currently I use something like this:

<xsl:template match="aName">
    <xsl:element name="differentName">
        <xsl:attribute name="att1">...</xsl:attribute>
        <xsl:attribute name="att2">...</xsl:attribute>
        <xsl:attribute name="att3">...</xsl:attribute>
        <xsl:copy-of select='./*'/>
    ...
    </xsl:element>
...
</xsl:template>

which I don't think is ugly and get locked with those explicit attribute definitions.

Any opinion?


lexzeus September 4th, 2006 08:49 AM

typo

>which I don't think is ugly and get locked with those explicit attribute definitions.

which I do think is ugly and get locked with those explicit attribute definitions.


lexzeus September 4th, 2006 08:55 AM

<xsl:template match="aName">
    <xsl:element name="differentName">
        <xsl:copy-of select='./@*'/>
        <xsl:copy-of select='./*'/>
    ...
    </xsl:element>
...
</xsl:template>

This will define new name but retain the attributes and children..
Other way more straight forward than this, anyone?



mhkay September 4th, 2006 09:04 AM

You can copy all the attributes using <xsl:copy-of select="@*"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


All times are GMT -4. The time now is 11:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.