Gomolyako Eduard wrote:
U need only one template in your stylesheet for this:
<xsl:template match="/ProductList">
<ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:copy-of select="." />
</ProductDataSet>
</xsl:template>
No, that's not enough. xsl:copy-of copies element as is and so if in
source XML an element is in no namespace, it will be in no namespace in
output, XSLT processor must emit xmlns="" to the Product element then.
Try something like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="ProductList">
<ProductList xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates select="@*|node()"/>
</ProductList>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}"
namespace="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
If in your XML there is no attributes, comments or PIs, this can be
simplified to
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="ProductList">
<ProductList xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates/>
</ProductList>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}"
namespace="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net |
http://www.XLinq.Net |
http://blog.tkachenko.com