How to reorder XML in an xmlType
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