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!

How to reorder XML in an xmlType

paul brownMar 29 2012 — edited Mar 30 2012
I'm a bit of a newbie to this so have patience.
I have an XML doc in an xmlType that I want to reorder.
I have tried this:

CREATE OR REPLACE PROCEDURE TEST_XSL AS
v_template xmlType;
v_src xmlType;
v_result xmlType;
begin
v_template := xmlType('<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'
|| '<xsl:template match="/">'
|| '<xsl:for-each select="scat">'
|| '<xsl:sort order="ascending" select="service"/>'
|| ' </xsl:for-each>'
|| '</xsl:template>'
|| '</xsl:stylesheet>');

v_src := xmlType('
<scat name="Hair Treatments" type="5">
<service name="name2">def</service>
<service name="name1">abc</service>
</scat>');
v_result := v_src.transform(v_template);

htp.p(xmltype.extract(v_result, '/*').getStringVal());

exception
when others then
htp.p('<hr>'||dbms_utility.format_error_stack);
htp.p('<hr>'||dbms_utility.format_error_backtrace);
END TEST_XSL;

but no joy.
I want to end up with the original XML doc, but reordered. The actual doc I need to reorder is very large and far more complicated, but I'm just trying to understand the basics.
Many Thanks for the help
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2012
Added on Mar 29 2012
10 comments
571 views