Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Declaring namespace prefix in result of transformation >Thread Next - Re: Declaring namespace prefix in result of transformation Re: Declaring namespace prefix in result of transformationTo: 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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
