Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt to dynamically re-namespace elements

Reply
Thread Tools

xslt to dynamically re-namespace elements

 
 
wooks
Guest
Posts: n/a
 
      01-03-2004
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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> <
<xslutput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xslaram 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?
 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      01-04-2004
In article <(E-Mail Removed) >,
wooks <(E-Mail Removed)> wrote:

% <xsl:stylesheet
% xmlnssl="http://www.w3.org/1999/XSL/Transform"
% version="1.0"> <
% <xslutput method="xml" version="1.0" encoding="UTF-8"
% indent="yes"/>
% <xslaram 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
wooks
Guest
Posts: n/a
 
      01-06-2004
(E-Mail Removed) (Patrick TJ McPhee) wrote in message news:<bt7t9l$mn7$(E-Mail Removed)>...
> In article <(E-Mail Removed) >,
> wooks <(E-Mail Removed)> wrote:
>
> % <xsl:stylesheet
> % xmlnssl="http://www.w3.org/1999/XSL/Transform"
> % version="1.0"> <
> % <xslutput method="xml" version="1.0" encoding="UTF-8"
> % indent="yes"/>
> % <xslaram 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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xslaram 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
Multiple XSLT Transforms using a Controller XSLT sneill@mxlogic.com XML 2 10-19-2005 11:00 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments