11 Replies Latest reply: Oct 11, 2012 2:27 AM by user7932928 RSS

    copyEvolve supports XSL 2.0?

    Denny Wong-Oracle
      I want to know if the copyEvolve supports XSL version 2.0? The example I seen so far only support version 1.0.

      Thanks.
        • 1. Re: copyEvolve supports XSL 2.0?
          730428
          There's no support of XSLT 2.0 in Oracle XMLDB at least until version 11.1.0.6

          I got three simple xslt documents:

          Test10.xsl
          <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
          <xsl:template match="/">
          <output>
            <xsl:value-of select="./A/text()"/>
          </output>
          </xsl:template>
          </xsl:transform>
          Test12.xsl
          <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
          <xsl:template match="/">
          <output>
            <xsl:value-of select="./A/text()"/>
          </output>
          </xsl:template>
          </xsl:transform>
          Test20.xsl
          <xsl:transform 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:str="http://user.com/namespace"
            version="2.0"
            exclude-result-prefixes="str">
          
          <xsl:function name="str:reverse">
            <xsl:param name="sentence"/>
            <xsl:result 
               select="if (contains($sentence, ' '))
                       then concat(str:reverse(substring-after($sentence, ' ')),
                                   ' ',
                                   substring-before($sentence, ' '))
                       else $sentence"/>             
          </xsl:function>
          
          <xsl:template match="/">
          <output>
            <xsl:value-of select="str:reverse('DOG BITES MAN')"/>
          </output>
          </xsl:template>
          
          </xsl:transform>
          Then I loaded them into XMLDB:
          SQL> select banner from v$version;
          
          BANNER
          --------------------------------------------------------------------------------
          Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
          PL/SQL Release 11.1.0.6.0 - Production
          CORE    11.1.0.6.0      Production
          TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
          NLSRTL Version 11.1.0.6.0 - Production
          
          SQL> DECLARE
            2      res BOOLEAN;
            3  BEGIN
            4    res := DBMS_XDB.createResource(
            5           '/test10.xsl',
            6           bfilename('FILE_DIR', 'test10.xsl'),
            7           nls_charset_id('AL32UTF8'));
            8  END;
            9  /
          
          Procedura PL/SQL completata correttamente.
          
          SQL>
          SQL> DECLARE
            2      res BOOLEAN;
            3  BEGIN
            4    res := DBMS_XDB.createResource(
            5           '/test12.xsl',
            6           bfilename('FILE_DIR', 'test12.xsl'),
            7           nls_charset_id('AL32UTF8'));
            8  END;
            9  /
          
          Procedura PL/SQL completata correttamente.
          
          SQL>
          SQL> DECLARE
            2    res BOOLEAN;
            3  BEGIN
            4    res := DBMS_XDB.createResource(
            5           '/test20.xsl',
            6           bfilename('FILE_DIR', 'test20.xsl'),
            7           nls_charset_id('AL32UTF8'));
            8  END;
            9  /
          
          Procedura PL/SQL completata correttamente.
          And finally tried to use them to transform a simple XML:
          SQL> select xmltransform(xmltype('<A>xxx</A>'),
            2                      DBMS_XDB.GETCONTENTXMLTYPE('/test10.xsl')
            3                     ) test
            4  from dual;
          
          TEST
          ----------------------------------------------------------------------
          <output>xxx</output>
          
          SQL> select xmltransform(xmltype('<A>xxx</A>'),
            2                      DBMS_XDB.GETCONTENTXMLTYPE('/test12.xsl')
            3                     ) test
            4  from dual;
          
          TEST
          ---------------------------------------------------------------------
          <output>xxx</output>
          
          SQL> select xmltransform(xmltype('<A>xxx</A>'),
            2                      DBMS_XDB.GETCONTENTXMLTYPE('/test20.xsl')
            3                     ) test
            4  from dual;
          ERROR:
          ORA-31011: Analisi XML non riuscita
          ORA-19202: Errore durante l'elaborazione XML
          LPX-00602: Invalid child element 'function' of element 'transform'.
          Hence:
          1) Using an xslt document tagged version="2.0" but containing only 1.0 elements works
          2) Using an xslt 2.0 new feature (user defined functions) doesn't work
          3) I didn't make a specific test on copyEvolve, but a generic test on XSLT processor
          4) Version 11.1.0.6

          Max
          [My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/07/creare-documenti-office-da-plsql/]
          • 2. Re: copyEvolve supports XSL 2.0?
            mdrake-Oracle
            Currently the XSLT Virtual machine only supports XSLT 1.0.
            • 3. Re: copyEvolve supports XSL 2.0?
              Pollocks01
              Is there any way to do XSLT 2.0 transformations within Oracle using native Oracle features?

              ......or would I have to create a wrapper to the Saxon engine, for example?

              Please advise....
              • 4. Re: copyEvolve supports XSL 2.0?
                Marco Gralike
                I guess currently you are still out of luck. Wrapper could work
                • 5. Re: copyEvolve supports XSL 2.0?
                  Pollocks01
                  thanks.....

                  I tried the XDK wrapper posted here: XDK XSLT proccessor alternative

                  ...but get an error:

                  ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.xpath.XPathException: Parse Error in format-date function.
                  ORA-06512: at "ERS_DEM1.XDK_XSL_TRANSFORM", line 1
                  ORA-06512: at line 6

                  I'm now trying to load the saxon jar and create a wrapper to that. I successfully use saxon thru' Eclipse to do transformations.

                  It is frustrating that Oracle appears unable to to 2.0 transformations...........
                  • 6. Re: copyEvolve supports XSL 2.0?
                    odie_63
                    Hi,

                    I get the same error with XDK 11g and format-date XSL function :
                    DECLARE
                    
                      output clob;
                    
                      xml_input clob := '<root dt="2011-05-18">
                         <item type="T1"><val>1</val></item>
                         <item type="T2"><val>4</val></item>
                         <item type="T3"><val>2</val></item>
                         <item type="T1"><val>1</val></item>
                         <item type="T1"><val>1</val></item>
                         <item type="T2"><val>8</val></item>
                    </root>';
                    
                    
                      xsl_input clob := '<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                      <xsl:output method="xml" indent="yes"/>
                      <xsl:template match="/">
                           <result date="{format-date(root/@dt,''[D01]/[M01]/[Y]'')}">
                          <xsl:for-each-group select="root/item" group-by="@type">
                            <xsl:sort select="@type"/>
                            <type>
                                 <name><xsl:value-of select="current-grouping-key()"/></name>
                                 <total><xsl:value-of select="sum(current-group()/val)"/></total>
                               </type>
                          </xsl:for-each-group> 
                        </result>
                      </xsl:template>
                    </xsl:stylesheet>';
                    
                    BEGIN
                     
                      dbms_lob.createtemporary(output, true);
                      xdk_xsl_transform(xml_input, xsl_input, output);
                      dbms_output.put_line(output);
                      dbms_lob.freetemporary(output);
                      
                    END;
                    /
                    Hopefully, some XSLT 2.0 features work as expected :
                    SQL> DECLARE
                      2  
                      3    output clob;
                      4  
                      5    xml_input clob := '<root dt="2011-05-18">
                      6       <item type="T1"><val>1</val></item>
                      7       <item type="T2"><val>4</val></item>
                      8       <item type="T3"><val>2</val></item>
                      9       <item type="T1"><val>1</val></item>
                     10       <item type="T1"><val>1</val></item>
                     11       <item type="T2"><val>8</val></item>
                     12  </root>';
                     13  
                     14  
                     15    xsl_input clob := '<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                     16    <xsl:output method="xml" indent="yes"/>
                     17    <xsl:template match="/">
                     18         <result>
                     19        <xsl:for-each-group select="root/item" group-by="@type">
                     20          <xsl:sort select="@type"/>
                     21          <type>
                     22               <name><xsl:value-of select="current-grouping-key()"/></name>
                     23               <total><xsl:value-of select="sum(current-group()/val)"/></total>
                     24             </type>
                     25        </xsl:for-each-group>
                     26      </result>
                     27    </xsl:template>
                     28  </xsl:stylesheet>';
                     29  
                     30  BEGIN
                     31  
                     32    dbms_lob.createtemporary(output, true);
                     33    xdk_xsl_transform(xml_input, xsl_input, output);
                     34    dbms_output.put_line(output);
                     35    dbms_lob.freetemporary(output);
                     36  
                     37  END;
                     38  /
                     
                    <?xml version = '1.0' encoding = 'UTF-8'?>
                    <result>
                       <type>
                          <name>T1</name>
                          <total>3</total>
                       </type>
                       <type>
                          <name>T2</name>
                          <total>12</total>
                       </type>
                       <type>
                          <name>T3</name>
                          <total>2</total>
                       </type>
                    </result>
                     
                    PL/SQL procedure successfully completed
                     
                    According to the documentation, the implementation of XSLT 2.0 is based on the 2003 W3C working draft, which describes format-date function :
                    http://www.w3.org/TR/2003/WD-xslt20-20030502/#format-date
                    But apparently, it's not fully functional.

                    Edit : format-number() works as well.

                    Edited by: odie_63 on 18 mai 2011 23:32
                    • 7. Re: copyEvolve supports XSL 2.0?
                      Pollocks01
                      odie_63,

                      Great info - thanks...so there is hope for Oracle XSLT functionality, but unless we hook our XSLT IDE up with the Oracle XSLT processor (which should be possible because it's just a bunch of classes/jars), then it's pretty tough to develop XSLT 2.0 transformation that we know will work within Oracle.

                      I successfully loaded the saxon jar and implemented a small Java class and pl/sql wrapper that allows me to execute all the transformations that I develop in Eclipse within Oracle :-)

                      For a solution that doesn't need to work under heavy load, then I'm happy enough with 'hack'.

                      -P
                      • 8. Re: copyEvolve supports XSL 2.0?
                        odie_63
                        I successfully loaded the saxon jar
                        Just for my information, did you get any error in the loading process? Unresolved classes, etc. ?

                        Which version of Saxon are you using? on which database version?

                        Another solution I use sometimes is calling the Saxon engine from the database through a DBMS_SCHEDULER external job.
                        But that implies to first write both XML source and stylesheet to the file system.
                        • 9. Re: copyEvolve supports XSL 2.0?
                          Pollocks01
                          Odie,

                          When I executed loadjava from my 10g client bin directory, I got a lot of what appeared to be class resolution issues. I then did a loadjava just from the C: prompt (only have one oracle client so can't understand what happened here...), and it loaded the jar just fine! Over 1300 java classes got registered.

                          Server is 11gR2 Enterprise Edn (not sure exactly which version) and I am prototyping with Saxon 9.3 Home edition.

                          It appears to work!

                          Despite this success, I'm going to see if I can workaround the issue re: format-date and use the Oracle xdk instead.....

                          -P
                          • 10. Re: copyEvolve supports XSL 2.0?
                            Pollocks01
                            ....yes, command line invocation of Saxon would also work but I like the java wrapper's ability to pass params in and out ;-)
                            • 11. Re: copyEvolve supports XSL 2.0?
                              user7932928
                              Hi

                              I just saw this thread and it's very similar so something I'm trying to do.. What version of Saxon did you load - and could you post the code to your wrapper?

                              Thanks

                              Shafiq