Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XMLType.Transform() and namespace

650745Nov 12 2008 — edited Nov 14 2008
Hi there,

My server is Oracle9i Enterprise Edition Release 9.2.0.6.0.

I am trying to transform an input XML fragment into an output XML fragment using XMLType.Transform().
It works well when no namespace attribute is present in the input XML.

For example:

<<<code>>>
DECLARE
lxml XMLTYPE := XMLTYPE('<Movement>
<NOTF_ID>1022914300</NOTF_ID>
<SNUN_CDE>BE40309029-0101</SNUN_CDE>
<ANML_REF_NBR>BE 6 43301900</ANML_REF_NBR>
<NOTP_CDE>MMDPR</NOTP_CDE>
<OCR_DTE>2008-11-05T00:00:00</OCR_DTE>
</Movement>');

lxsl XMLTYPE := XMLTYPE('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="Movement">
<Movement>
<xsl:copy-of select="./NOTF_ID"/>
<xsl:copy-of select="./ANML_REF_NBR"/>
<xsl:copy-of select="./OCR_DTE"/>
</Movement>
</xsl:template>
</xsl:stylesheet>');
lstr VARCHAR2(4000);
BEGIN
lxml := lxml.TRANSFORM(lxsl);

-- show the result
lstr := lxml.getStringVal();
WHILE LENGTH(lstr) > 0
LOOP
DBMS_OUTPUT.PUT_LINE(SUBSTR(lstr,1,255));
lstr := SUBSTR(lstr,256);
END LOOP;
END;
/
<<<code>>>

The result is exactly what I want it to be:

<<<output>>>
<Movement>
<NOTF_ID>1022914300</NOTF_ID>
<ANML_REF_NBR>BE 6 43301900</ANML_REF_NBR>
<OCR_DTE>2008-11-05T00:00:00</OCR_DTE>
</Movement>
<<<output>>>

However, when a namespace attribute is present on the root element of the input XML, the transformation result is not what want:

<<<code>>>
DECLARE
lxml XMLTYPE := XMLTYPE('<Movement xmlns="http://some_url">
<NOTF_ID>1022914300</NOTF_ID>
<SNUN_CDE>BE40309029-0101</SNUN_CDE>
<ANML_REF_NBR>BE 6 43301900</ANML_REF_NBR>
<NOTP_CDE>MMDPR</NOTP_CDE>
<OCR_DTE>2008-11-05T00:00:00</OCR_DTE>
</Movement>');

lxsl XMLTYPE := XMLTYPE('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="Movement">
<Movement>
<xsl:copy-of select="./NOTF_ID"/>
<xsl:copy-of select="./ANML_REF_NBR"/>
<xsl:copy-of select="./OCR_DTE"/>
</Movement>
</xsl:template>
</xsl:stylesheet>');
lstr VARCHAR2(4000);
BEGIN
lxml := lxml.TRANSFORM(lxsl);

-- show the result
lstr := lxml.getStringVal();
WHILE LENGTH(lstr) > 0
LOOP
DBMS_OUTPUT.PUT_LINE(SUBSTR(lstr,1,255));
lstr := SUBSTR(lstr,256);
END LOOP;
END;
/
<<<code>>>

This results in a concatenation of all element-values in the input XML:

<<<output>>>
1022914300BE40309029-0101BE 6 43301900MMDPR2008-11-05T00:00:00
<<<output>>>

My question is: how to formulate the stylesheet in such a way that the namespace attribute in the input XML is either ignored, or just copied to the output XML ?

Any suggestions?

Thanks,
Jaap Kool
This post has been answered by Jason_(A_Non) on Nov 13 2008
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 12 2008
Added on Nov 12 2008
5 comments
2,770 views