0

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?

4
  • 1
    Schemas don't define any prefixes, they define target namepaces. Commented May 29, 2017 at 12:15
  • Yes, that's true. I'm working with the assumption it's OK to just assign a working prefix to use within the XSLT, and expect it to recognize the URI found in the instance no matter what the instance uses as a prefix? Commented May 29, 2017 at 12:25
  • The instances I need to transform will use the prefix defined as a convenience in the schemas and both (1) and (2) use the same prefix for 2 different URIs. Commented May 29, 2017 at 12:26
  • 1
    Can you post minimal but complete snippets of XML input, XML output and XSLT you have tried? As you say you have one input format you want to transform to a second output format I am not sure why you see problems with a prefix, you can certainly write e.g. <xsl:template match="pf:foo" xmlns:pf="http://example.com"><pf:bar xmlns:pf="http://example.org">...</pf:bar></xsl:template> Commented May 29, 2017 at 12:32

1 Answer 1

2

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"/>
Sign up to request clarification or add additional context in comments.

1 Comment

This was my working assumption 2 mins after posting. Once I get a finished XSLT going that is based on this I'll close the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.