I have an XSL that is transforming one XSD into another XSD that has slightly different formatting. (Basically, the target file will be normalized). The other major difference in the target is adding a default namespace and a target namespace. I’m having trouble actually getting the namespace in. Here is a snippet of my XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"/>
<xsl:variable name="Unions" select="'Yes'"/>
<xsl:variable name="myname" select="//Table/Name"/>
<xsl:variable name="namespace" select="concat('http://mynamespace/', $myname)"/>
<xsl:template match="/">
<xsl:element name="xsd:schema" namespace="http://www.w3.org/2001/XMLSchema" xmlns="$namespace"
<xsl:attribute name="targetNamespace">
<xsl:value-of select="$namespace"/>
</xsl:attribute>
<xsl:attribute name="elementFormDefault">qualified</xsl:attribute>
<xsl:attribute name="attributeFormDefault">unqualified</xsl:attribute>
...
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And this is what I’m getting:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="http://mynamespace/somename" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="">
...
</xsd:schema>
And xmlns=”$namespace” is tagged on to every child node. I’m no absolute expert on XSLT. I have not had to develop it myself because BizTalk maps generate all of it for you, but this XSL was more complex than I could get BizTalk maps to handle.
Oh, and I’m limited to XSLT 1.0
Generating namespace nodes with dynamically generated values is something XSLT 1 can’t really do. XSLT 2 adds
xsl:namespacespecifically to construct such things.You said you are stuck at XSLT 1. Do you have EXSLT or any other extension namespace available that gives you the node-set() extension? If so you can go
Creating a spurious element
<x>in the desired namespace, this forces the namespace node on to its childxs:schemaelement which you can extract if you have a node-set extension function.