xslt to dynamically re-namespace elements

Discussion in 'XML' started by wooks, Jan 3, 2004.

  1. wooks

    wooks Guest

    I want to apply 2 changes to the following xml

    <ROOTSTUB app="appname"/>

    1. change the app attribute to an element.
    2. put the ROOTSTUB element into a namespace that is passed as a
    global parameter at run time.


    so I want

    <ROOTSTUB xmlns="urn:aNamespace">
    <app>appname</app>
    </ROOTSTUB>

    and I'd like to do it in one pass. I have tried

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"> <
    <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
    indent="yes"/>
    <xsl:param name="namespace"/>
    <xsl:template match="node()|@*">
    <xsl:element name="{local-name(.)}" namespace="$namespace">
    <xsl:value-of select= "." />
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

    and variations thereof. I cannot get the output I desire.
    Can anyone else?
    wooks, Jan 3, 2004
    #1
    1. Advertising

  2. In article <>,
    wooks <> wrote:

    % <xsl:stylesheet
    % xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    % version="1.0"> <
    % <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
    % indent="yes"/>
    % <xsl:param name="namespace"/>
    % <xsl:template match="node()|@*">

    You probably want this to match just "*|@*" (elements and attributes).
    You'll want another template matching and copying other nodes
    <xsl:template match="node()">
    <xsl:copy-of select ='.'/>
    </xsl:template>

    % <xsl:element name="{local-name(.)}" namespace="$namespace">
    % <xsl:value-of select= "." />
    % </xsl:element>

    how about

    <xsl:element name="{local-name(.)}" namespace="{$namespace}">
    <xsl:apply-templates select= "node()|@*" />
    </xsl:element>

    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Jan 4, 2004
    #2
    1. Advertising

  3. wooks

    wooks Guest

    (Patrick TJ McPhee) wrote in message news:<bt7t9l$mn7$>...
    > In article <>,
    > wooks <> wrote:
    >
    > % <xsl:stylesheet
    > % xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > % version="1.0"> <
    > % <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
    > % indent="yes"/>
    > % <xsl:param name="namespace"/>
    > % <xsl:template match="node()|@*">
    >
    > You probably want this to match just "*|@*" (elements and attributes).
    > You'll want another template matching and copying other nodes
    > <xsl:template match="node()">
    > <xsl:copy-of select ='.'/>
    > </xsl:template>
    >
    > % <xsl:element name="{local-name(.)}" namespace="$namespace">
    > % <xsl:value-of select= "." />
    > % </xsl:element>
    >
    > how about
    >
    > <xsl:element name="{local-name(.)}" namespace="{$namespace}">
    > <xsl:apply-templates select= "node()|@*" />
    > </xsl:element>


    I finally got this to work using a variation of your suggestion as below. Thanks

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:param name="namespace"/>
    <xsl:template match="*">
    <xsl:element name="{local-name(.)}" namespace="{$namespace}">
    <xsl:apply-templates select= "node()|@*" />
    </xsl:element>
    </xsl:template>
    <xsl:template match="@*">
    <xsl:element name="{local-name(.)}" namespace="{$namespace}">
    <xsl:value-of select= "." />
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>
    wooks, Jan 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Èý¹â
    Replies:
    1
    Views:
    565
    William F. Robertson, Jr.
    Jul 29, 2003
  2. Replies:
    0
    Views:
    5,126
  3. Anonymous
    Replies:
    3
    Views:
    529
    Ron Natalie
    Aug 18, 2003
  4. Jason Heyes
    Replies:
    1
    Views:
    448
    Woebegone
    Nov 19, 2004
  5. Gerald Aichholzer
    Replies:
    2
    Views:
    2,492
    Gerald Aichholzer
    Jun 27, 2006
Loading...

Share This Page