Mayur Jaiswal
Mayur Jaiswal

Reputation: 1

XSLT Transformation Adding NameSpace Prefix Not Working On Oracle 10g

I am currently facing issue with the below Transformation on Oracle 10g (10.2.0.4.0) adding the namespace prefix using XSLT on the XML.

    SELECT XMLTRANSFORM(XMLTYPE('<EMP xmlns:xsd="http://lgi/vitria/wil/xsd">
  <FIRST_NAME>680394-catv</FIRST_NAME>
  <LAST_NAME>1414145</LAST_NAME>
  <PHONE>0522222532</PHONE>
</EMP>
'),XMLTYPE('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsd="http://lgi/vitria/wil/xsd">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

  <xsl:template match="*" >
      <xsl:element name="xsd:{local-name()}">
          <xsl:apply-templates select="@* | node()"/>
      </xsl:element>
  </xsl:template>  
</xsl:stylesheet>')) from dual
    
    

**Expected Output:**
<xsd:EMP xmlns:ns0="http://test">
  <xsd:FIRST_NAME>680394-catv</xsd:FIRST_NAME>
  <xsd:LAST_NAME>1414145</xsd:LAST_NAME>
  <xsd:PHONE>0522222532</xsd:PHONE>
</xsd:EMP>

**Current Output :** 
<EMP>
<FIRST_NAME>680394-catv</FIRST_NAME>
<LAST_NAME>1414145</LAST_NAME>
<PHONE>0522222532</PHONE>
</EMP>

I checked on a Higher release 10g(10.2.0.5.0) and it was working as expected. what would be best solution to make this work on 10g(10.2.0.4.0)

Upvotes: 0

Views: 97

Answers (1)

ChuckB
ChuckB

Reputation: 898

If the transform in your code applied to the XML in your code file yields exactly the output you show (with no namespace declaration), then there is most likely a bug in your XSLT engine. You should have a result that looks like what you expected, or else something like this:

<EMP xmlns="http://lgi/vitria/wil/xsd">
  <FIRST_NAME>680394-catv</FIRST_NAME>
  <LAST_NAME>1414145</LAST_NAME>
  <PHONE>0522222532</PHONE>
</EMP>

with the default namespace declaration on the EMP element, so that no namespace prefixes are needed.

You may already know this, but my sample output (default nameslace declaration and no prefixes) is from an XML perspective exactly equivalent to what you expected (namespace bound to the xsd prefix).

Your transform uses XSLT 1.0, so the [xslt-2.0] and [xslt-3.0] tags might be misleading to someone looking for 2.0- or 3.0-specific answers.

Upvotes: 0

Related Questions