Subject: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:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Article>
<MetaData>
<ID>618</ID>
<Type>Article</Type>
<Name>Article 1 Title</Name>
<State>Release</State>
<RouteTo>Nobody</RouteTo>
<PlacedOn>Layout 1</PlacedOn>
<PlacedOnPage>4-6</PlacedOnPage>
<Size>116179</Size>
<LengthWords>2525</LengthWords>
<LengthChars>15892</LengthChars>
<LengthLines>287</LengthLines>
<Modified>2008-11-24T14:03:54</Modified>
<Publication>My Publication</Publication>
<Issue>Test Issue</Issue>
<Section>Articles</Section>
<PublicationId>3</PublicationId>
<IssueId>65</IssueId>
<SectionId>14</SectionId>
<StateId>38</StateId>
<LockForOffline>false</LockForOffline>
</MetaData>
</Article>
This XML structure needs to be converted into XML with prefixes. Something like:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:htm="http://www.w3.org/1999/xhtml"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:pcv="http://prismstandard.org/namespaces/1.2/pcv/"
xmlns:prism="http://prismstandard.org/namespaces/1.2/basic/">
<rdf:Description>
<dc:identifier>618</dc:identifier>
<dc:filetype>Article</dc:filetype>
<dc:Name>Article 1 Title</dc:Name>
<dc:State>Release</dc:State>
<dc:RouteTo>Nobody</dc:RouteTo>
<prism:PlacedOn>Layout 1</prism:PlacedOn>
<prism:PlacedOnPage>4-6</prism:PlacedOnPage>
<dc:Size>116179</dc:Size>
<dc:LengthWords>2525</dc:LengthWords>
<dc:LengthChars>15892</dc:LengthChars>
<dc:LengthLines>287</dc:LengthLines>
<prism:Modified>2008-11-24T14:03:54</prism:Modified>
<prism:Publication>My Publication</prism:Publication>
<dc:Issue>Test Issue</dc:Issue>
<dc:Section>Articles</dc:Section>
<dc:PublicationId>3</dc:PublicationId>
<dc:IssueId>65</dc:IssueId>
<dc:SectionId>14</dc:SectionId>
<dc:StateId>38</dc:StateId>
<dc:LockForOffline>false</dc:LockForOffline>
</rdf:Description>
</rdf:RDF>
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.
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.
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="...">