Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: 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 6:13:00 PM Alex Yackimoff wrote: > "Martin Honnen" <mahotrash@y...> wrote in message > news:Of1veySjJHA.1184@T...... >> With XSLT 2.0 there is an xsl:namespace element >> (http://www.w3.org/TR/xslt20/#creating-namespace-nodes) to create a >> namespace declarations: > > Thanks, Martin. Works great. So, there's no way of doing that with XSLT 1.0? I think you would either need to chain two stylesheets or you would need to use an extension function like exsl:node-set or msxsl:nod-set: <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" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:variable name="tns-rtf"> <dummy-root> <xsl:if test="xs:schema/@targetNamespace"> <xsl:element name="tns:dummy" namespace="{xs:schema/@targetNamespace}"/> </xsl:if> </dummy-root> </xsl:variable> <xsl:variable name="tns" select="exsl:node-set($tns-rtf)/dummy-root/*"/> <Types> <xsl:copy-of select="$tns/namespace::*[local-name() = 'tns']"/> <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:choose> <xsl:when test="/xs:schema/@targetNamespace"> <xsl:value-of select="concat('tns:', @name)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="@name"/> </xsl:otherwise> </xsl:choose> </Value> </Property> </xsl:template> </xsl:stylesheet> That stylesheet creates a result-tree-fragment with an element in the targetNamespace, then uses the extension function to convert the result-tree-fragment to a node-set and then copies the namespace declaration node to the result tree (all that only if the schema being processed has a targetNamespace attribute). That is rather convoluted but I can't find an easier way with XSLT 1.0. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
