Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Declaring namespace prefix in result of transformation

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 2/12/2009 5:12:00 PM
Alex Yackimoff wrote:

> I need to extract the list of complex types from (any) XML schema and save 
> it in an appopriate XML with this structure (fragment represents a single 
> item of the list):
> 
>   <Property name="ParameterItemDef">
>     <Value xsi:type="xs:QName">tns:ParameterItemDef</Value>
>   </Property>
> 
> where ParameterItemDef is the name of the complex type in schema. What I 
> can't figure out is how to bind "tns" prefix to the targetNamespace of the 
> input schema (how to dynamically create xmlns attribute).
> 
> XSLT 1.0 is preferred. However, XSLT 2 way would also be welcome.

With XSLT 2.0 there is an xsl:namespace element 
(http://www.w3.org/TR/xslt20/#creating-namespace-nodes) to create a 
namespace declarations:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   version="2.0">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="/">
     <Types>
       <xsl:if test="xs:schema/@targetNamespace">
         <xsl:namespace name="tns" select="xs:schema/@targetNamespace"/>
       </xsl:if>
       <xsl:apply-templates select="descendant::xs:complexType[@name]"/>
     </Types>
   </xsl:template>

   <xsl:template match="xs:complexType">
     <Property name="{@name}">
       <Value xsi:type="xs:QName">
         <xsl:value-of select="if (/xs:schema/@targetNamespace) then 
concat('tns:', @name) else @name"/>
       </Value>
     </Property>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent