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
|