Why does the following not work as I’d expect it to?
<root xmlns:ns0="xmlns"
ns0:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1="xsi"
ns1:schemaLocation="[some schema location]" />
Basically, I’m trying to add schemaLocation to an xml file that doesn’t have this by doing :-
<xsl:template match="/s:*">
<xsl:element name="{local-name()}" namespace="some other namespace">
<xsl:attribute namespace="xmlns" name="xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>
<xsl:attribute namespace="xsi" name="schemaLocation">[some-loc]</xsl-attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
and Xalan-C gives the xml shown above.
What I’m trying to get is something like :-
<root xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance"
ns0:schemaLocation="[some schema location]" />
You need
<xsl:attribute name="xsi:schemaLocation">[some-loc]</xsl:attribute>.Edit (adding complete example):
Depending on what exactly you’re doing you can possibly use
<xsl:copy>to copy the element instead of<xsl:element name="{local-name()}"/>; it’s somewhat simpler.