Reputation: 285
I want to transform an XML instance that validates against schema (2) into an instance that validates against the old schema (1).
The 2 schemas use different namespace URIs but share the same element name prefix for those URIs.
Is the only workaround just to change the namespace prefix used in the input before transforming? Or can it be built into the XSLT?
Upvotes: 0
Views: 611
Reputation: 116993
Is the only workaround just to change the namespace prefix used in the input before transforming?
No, the solution is to use a different prefix for the source XML namespace in the stylesheet. Here's a minimal example:
XML
<abc:root xmlns:abc="www.example.com/source"/>
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:src="www.example.com/source"
xmlns:abc="www.example.com/target"
exclude-result-prefixes="src">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="src:*">
<xsl:element name="abc:{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Result
<?xml version="1.0" encoding="UTF-8"?>
<abc:root xmlns:abc="www.example.com/target"/>
Upvotes: 2