[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Iterating recursivly on a node changing the elemen

Subject: RE: Iterating recursivly on a node changing the element names
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Wed, 21 Nov 2007 08:25:32 -0600
RE:  Iterating recursivly on a node changing the elemen
Alternately:
<xsl:element name="{local-name()}" namespace="yourNamespaceURI">

~ Scott


-----Original Message-----
From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx]
Sent: Wednesday, November 21, 2007 4:18 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Iterating recursivly on a node changing the element
names

On 21/11/2007, ML mail <mlnospam@xxxxxxxxx> wrote:
> Dear list,
>
> I would like to modify the name of my elements of a
> certain node to
>  make it use a new namespace so for that I somehow
> need an iteration
>  process which goes through a specific node and adds a
> prefix to all of my
>  elements. Let's say I have the following:
>
> <start attr="myattr">
>     <two>
>         <three>3</three>
>         <four>4</four>
>     </two>
> </start>
>
> I need to make it look like this after processing:
>
> <nsprefix:start attr="myattr">
>     <nsprefix:two>
>         <nsprefix:three>3</nsprefix:three>
>         <nsprefix:four>4</nsprefix:four>
>     </nsprefix:two>
> </nsprefix:start>
>
>
> I started creating a template for that and defining
> all the nodes under
>  the start node but this sounds quite stupid because
> if there are many
>  different possibilites it makes a whole lot of checks
> to build. So I
>  was thinking it's much easier to just detect the
> start element and then
>  iterate through all of it's child elements (in my
> case: two, three four)
>  and add the prefix to these elements. Unfortunately I
> didn't manage to
>  do that. Can someone provide me help on how to
> acheive that ?

Use the standard identity template with a specific template to put
<start> and all of it's descendants into the namespace:

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

    <xsl:template match="*[ancestor-or-self::start]">
        <xsl:element name="nsprefix:{local-name()}">
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

...make sure "nsprefix" is mapped somewhere.


cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.