XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Andres GarciaSubject: Add a namespace
Author: Andres Garcia
Date: 02 Jun 2007 12:42 PM
Originally Posted: 02 Jun 2007 12:35 PM
Hello.
I have a xml input that can have or not a namespace defined. If not, I have to add a default one, like the following:

input:

<a>
<b>
xxx
</b>
</a>

expected output:

<rq:a xmlns:req="http://xyz">
<rq:b>
xxx
</rq:b>
</rq:a>


How can this be done with a xlst transformation?

Thanks in advance.

Postnext
Alberto MassariSubject: Add a namespace
Author: Alberto Massari
Date: 04 Jun 2007 03:18 PM
Hi Andres,
you should have a template matching the namespace-less node that generates the correct version:

<xsl:stylesheet version="1.0" xmlns:rq="http://xyz" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="*[namespace-uri()='']">
<xsl:element name="rq:{local-name(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

Hope this helps,
Alberto

Posttop
Andres GarciaSubject: Add a namespace
Author: Andres Garcia
Date: 05 Jun 2007 11:55 AM
Thanks very much Alberto. It is exactly what I needed.
andres.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.