1

The XML I am expecting is supposed to be only one url/urn (xmlns:urn="urn:123:456") like below:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
            xmlns:urn="urn:123:456"
            xmlns:exsl="http://exslt.org/common"
            extension-element-prefixes="exsl" exclude-result-prefixes="urn">

When used with the below namespace it's OK:

<Document xmlns="123:456" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

But recently I am receiving a different document with the same structure as before, only difference is the namespace like below:

<Document xmlns="789:123" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

My question is, is there any way that I can support both in the same XSLT file

Below is a sample of my XSLT file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:urn="urn:123:456"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl" exclude-result-prefixes="urn">

  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/urn:Document">
    <Profiles>
      <xsl:apply-templates select="*"/>
    </Profiles>
  </xsl:template>

  <xsl:template match="urn:File">
    <File>
      <FileId>
        <xsl:value-of select="urn:Id"/>
      </FileId>
      <FileDate>
        <xsl:value-of select="urn:Created"/>
      </FileDate>
    </File>
  </xsl:template>

  <xsl:template match="urn:Employee">
    <Information>
      <EmpName>
        <xsl:value-of select="urn:Personal/Name"/>
      </EmpName>
      <Age>
        <xsl:value-of select="urn:Personal/Age"/>
      </Age>
      .
      .
      .
    </Information>
  </xsl:template>
</xsl:stylesheet>
Rob
  • 14,746
  • 28
  • 47
  • 65
zyberjock
  • 337
  • 5
  • 19

1 Answers1

2

You could declare both namespaces, e.g.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ns1="urn:123:456"
xmlns:ns2="urn:789:123"
exclude-result-prefixes="ns1 ns2">

Then use a union expression for your matches and selections, for example:

<xsl:template match="/ns1:Document | /ns2:Document">
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51