Re: [xsl] Modifying namespace definitions in xs:schema elements

Subject: Re: [xsl] Modifying namespace definitions in xs:schema elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 10 Oct 2009 15:22:54 -0400
At 2009-10-10 21:09 +0200, Wolfgang Laun wrote:
given an XML Schema, I should split this schema into two parts,
according to properties of elements and complex/simpleTypes.
Basically, I've succeeded to do this, using a couple of XSLT
transformations. But...

The original schema contains <xs:schema ... xmlns="a.b"
targetNamespace="a.b" ...>. I would like to modify this for one of the
results of the filtering, to become, e.g., xmlns="a.b.c"
targetNamespace="a.b.c". (The ultimate goal is to separate the
definitions made by the splt schemas into two different namespaces.)


Exploring the set of attributes in xs:schema (by <xsl:choose>
<xsl:when test="true()"> <xsl:value-of
select="concat(namespace-uri(),local-name())"/>...) has shown me that
the namespace definitions (xmlns="...") are not passed to template


Namespace definitions are not passed to template processing as attribute nodes, but they are passed to template processing as namespace nodes.

Does this mean that what I want to be done cannot be achieved at all,
using XSLT techniques?

No, what you want can be done. I hope the example below helps.

. . . . . . Ken

T:\ftemp>type wolfgang.xml
<xs:schema xmlns:xs="";

<xs:element name="doc">


T:\ftemp>xslt2 wolfgang.xml wolfgang.xsl
<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns="a.b.c" xmlns:xs=""; targetNamespace="a.b.c">

<xs:element name="doc">

T:\ftemp>type wolfgang.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="";

<!--recreate the document element when encountered-->
<xsl:template match="xsd:schema">
  <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
    <xsl:copy-of select="@*"/>
    <!--replacing the target namespace information-->
    <xsl:namespace name="">a.b.c</xsl:namespace>
    <xsl:attribute name="targetNamespace">a.b.c</xsl:attribute>
    <!--rest of the document-->

<!--recostitute all other elements to avoid copying namespaces-->
<xsl:template match="*">
  <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
    <xsl:apply-templates select="@*,node()"/>

<xsl:template match="@* | comment() | processing-instruction">



Upcoming: hands-on code list, UBL, XSLT, XQuery and XSL-FO classes
in Copenhagen Denmark and Washington DC USA, October/November 2009
Interested in other classes?
Crane Softwrights Ltd.
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread