Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Adding unused namespace in output using xslt. >Thread Next - Re: Adding unused namespace in output using xslt. Re: Adding unused namespace in output using xslt.To: NULL Date: 10/7/2008 2:47:00 PM
Jan Obrestad wrote:
> I tried adding these namespaces to the xsl:styleshhet element, but they
> did not appear in the output xml.
> Do you have any idea how to achieve this?
Here is an example that declares the namespaces on the xsl:stylesheet
element and then copies them to the result tree for the newly created
root element:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.e2b.no/XMLSchema"
xmlns:e2bCard="http://www.e2b.no/XMLSchema/Card"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="{local-name()}">
<xsl:copy-of
select="document('')/xsl:stylesheet/namespace::*[name() != 'xsl']"/>
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
When you run that against
<?xml version="1.0" encoding="utf-8" ?>
<pf1:root xmlns:pf1="http://example.com/2008/ns1">
<pf1:foo>
<pf1:bar>baz</pf1:bar>
</pf1:foo>
</pf1:root>
then Visual Studio 2005 creates the following result document
<?xml version="1.0" encoding="utf-8"?><root
xmlns="http://www.e2b.no/XMLSchema"
xmlns:e2bCard="http://www.e2b.no/XMLSchema/Card"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<foo>
<bar>baz</bar>
</foo>
</root>
I don't understand why you would want
xsi:noNamespaceSchemaLocation="e2b_Invoice_Interchange_v3p0.xsd"
in the result as your result has a namespace so providing a
noNamespaceSchemaLocation does not make any sense to me. Nevertheless if
you really need it then simply add that attribute to the root with e.g.
<xsl:template match="/*">
<xsl:element name="{local-name()}">
<xsl:copy-of
select="document('')/xsl:stylesheet/namespace::*[name() != 'xsl']"/>
<xsl:attribute
name="xsi:noNamespaceSchemaLocation">e2b_Invoice_Interchange_v3p0.xsd</xsl:attribute>
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
The other two templates remain unchanged.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
