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
casper VoortmanSubject: XML to XML Namespace conversion
Author: casper Voortman
Date: 08 Dec 2008 03:35 AM
I have a question regarding writing an XSLT that converts XML into an XML that uses namespace prefixes in the element names. I have written some XSLT's and call myself fairly proficient in it, but namespaces and prefixes is completely new to me.

I have a sample XML file that looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
        <Name>Article 1 Title</Name>
        <PlacedOn>Layout 1</PlacedOn>
        <Publication>My Publication</Publication>
        <Issue>Test Issue</Issue>

This XML structure needs to be converted into XML with prefixes. Something like:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:htm="http://www.w3.org/1999/xhtml"
        <dc:Name>Article 1 Title</dc:Name>
        <prism:PlacedOn>Layout 1</prism:PlacedOn>
        <prism:Publication>My Publication</prism:Publication>
        <dc:Issue>Test Issue</dc:Issue>

Next to adding the prefixes to the xml, also some elements need to be renamed. I have tried writing an XSLT for it, but i keep having the problem that every element that i define in the XSLT get the xmlns information added to it as an attribute. Also i how can i add al xmlns attribute data to the root element like in the result sample.

The XSLT i tried to write, looks a little like:
<?xml version="1.0" encoding="UTF-8"?>
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"

    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <!-- Match 'Article'. -->
    <xsl:template match="Article">
        <!-- Define root element. -->
         <xsl:element name="rdf:RDF">
             <!-- Define description element. -->
             <xsl:element name="rdf:Description">

                 <!-- Define indentifier element. -->
                 <xsl:element name="dc:identifier">
                 <!-- Define format element. -->
                 <xsl:element name="dc:format">
                 <!-- Define language element. -->
                 <xsl:element name="dc:language">
                 <!-- Define page range element. -->
                 <xsl:element name="prism:pageRange">

Any help would be greatly appreciated, since i looked around these forums and the internet but the only examples i can find always seem to deal with the reverse method.


Casper Voortman

(Deleted User) Subject: XML to XML Namespace conversion
Author: (Deleted User)
Date: 08 Dec 2008 03:05 PM
Hi Casper,
if you want to create an element inside a specific namespace, you need to add to xsl:element the namespace="..." attribute. Or just write it as a literal <rdf:name xmlns:rdf="...">


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!  

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.