Paul Kiel's Data Integration Blog
Data integration using Xml / Xslt and anything else...






Subscribe to "Paul Kiel's Data Integration Blog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog..

  Thursday, May 17, 2007


I had an interesting problem to solve recently regarding Xml Schemas, XSLT and namespaces. The task was to use XSLT to create Xml Schema dynamically. This was something I had done before and figured I would pull upon previous work to give me a head start. The interesting part was the requirements around creating namespaces. Dynamically created namespaces can be tricky enough, especially if you are not yet using XSLT 2.0 as I was. The added feature was that I needed to use pre-defined namespace prefixes on those dynamically generated namespaces.

In short, I was tasked with generating namespaces in a resulting Xml Schema, based on data dynamically created at processing time, and with namespace prefixes predefined.

The tempation is to try something like this:

<xsl:attribute name="xmlns"><xsl:value-of select="$xmlns"/>xsl:attribute>

But that doesn't work. The solution is to create a dummy attribute and copy it to the result via the namespace axis and local-name.

In the scenario here, I want to create 3 namespaces, one for the default and target, a second for "common" components that are to be imported, and a third for "custom" components that are used for extensions.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://xmlns.myexample.com/v3" targetNamespace="http://xmlns.myexample.com/v3" xmlns:common="http://xmlns.myexample.com/common/v3" xmlns:custom="http://xmlns.myexample.com/custom/v3"

elementFormDefault ="qualified"
attributeFormDefault="unqualified">
<xsd:import
schemaLocation="common.xsd"/>
<xsd:import
schemaLocation="custom.xsd"/>
xsd:schema>

1:01:37 PM    comment []


Click here to visit the Radio UserLand website. © Copyright 2007 Paul Kiel.
Last update: 9/22/2007; 4:26:37 PM.

May 2007
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Feb   Jun