[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT 3.0 schema awareness vs non schema awareness

Subject: XSLT 3.0 schema awareness vs non schema awareness
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 27 Feb 2019 06:57:05 -0000
 XSLT 3.0 schema awareness vs non schema awareness
Hi all,
    Please consider following XSLT examples (I'm using the XSLT 3.0
version), and my questions thereafter,
(in the presented stylesheets, I'm using XPath 3.0's mapping expressions
[using the operator !]. But my question is not about the ! operator)

I'm using Saxon EE 9.9. Saxon EE 9.7 also produces similar results.

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<test>
   <val>5</val>
   <val>4</val>
   <val>3</val>
   <val>0</val>
   <val>2</val>
   <val>0</val>
   <val>1</val>
</test>

Stylesheet 1:
(in this stylesheet, I have an embedded schema & I'm performing schema
aware transformation)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:xs="http://www.w3.org/2001/XMLSchema"
                        xmlns:fn="http://xslt-functions"
                        exclude-result-prefixes="xs fn"
                        version="3.0">

    <xsl:output method="xml" indent="yes"/>

    <!-- an XML schema imported into the stylesheet -->
    <xsl:import-schema>
       <xs:schema>
          <xs:element name="test">
             <xs:complexType>
                <xs:sequence>
                   <xs:element name="val" type="xs:integer"
maxOccurs="unbounded"/>
                </xs:sequence>
             </xs:complexType>
          </xs:element>
       </xs:schema>
    </xsl:import-schema>

    <xsl:template match="/">
       <result>
          <xsl:variable name="x" select="test/val"/>
          <xsl:copy-of select="$x!fn:sum(., 5)"/>
       </result>
    </xsl:template>

    <!-- function to add two numbers -->
    <xsl:function name="fn:sum" as="xs:integer">
       <xsl:param name="num" as="xs:integer" />
       <xsl:param name="incr" as="xs:integer" />

       <xsl:sequence select="$num + $incr"/>
    </xsl:function>

</xsl:stylesheet>

The above stylesheet, when applied to the input XML, produces following
output,

<?xml version="1.0" encoding="UTF-8"?>
<result>10 9 8 5 7 5 6</result>

Stylesheet 2:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
                         xmlns:fn="http://xslt-functions"
                         exclude-result-prefixes="xs fn"
                         version="3.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
       <result>
          <xsl:variable name="x" select="test/val" as="xs:integer*"/>
          <xsl:copy-of select="$x!fn:sum(., 5)"/>
       </result>
    </xsl:template>

    <!-- function to add two numbers -->
    <xsl:function name="fn:sum" as="xs:integer">
       <xsl:param name="num" as="xs:integer" />
       <xsl:param name="incr" as="xs:integer" />

       <xsl:sequence select="$num + $incr"/>
    </xsl:function>

</xsl:stylesheet>

In above stylesheet, I don't use an embedded schema and don't use schema
aware transformation. In the above stylesheet, I add the syntax
*as="xs:integer*"* to variable declaration <xsl:variable name="x" ...
The stylesheet above, produces same output as Stylesheet 1 when applied to
the same input XML document.

Stylesheet 3:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
                         xmlns:fn="http://xslt-functions"
                         exclude-result-prefixes="xs fn"
                         version="3.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
       <result>
          <xsl:variable name="x" select="test/val" />
          <xsl:copy-of select="$x!fn:sum(., 5)"/>
       </result>
    </xsl:template>

    <!-- function to add two numbers -->
    <xsl:function name="fn:sum" as="xs:integer">
       <xsl:param name="num" as="xs:integer" />
       <xsl:param name="incr" as="xs:integer" />

       <xsl:sequence select="$num + $incr"/>
    </xsl:function>

</xsl:stylesheet>

In the above stylesheet, I don't use *as="xs:integer*"* on the mentioned
variable. Otherwise, the above stylesheet is same as Stylesheet 2.
The stylesheet above, produces same output as stylesheets 1 and 2 when
applied to the same input XML document.

That is, all above three stylesheets produce same output with the same
input XML document.

I wish to know the, pros and cons when comparing above three mentioned
stylesheets, in terms of functionality, performance and may be other
factors. I guess, schema aware transformations in general, are more suited
when rigorous static type checking is needed.




-- 
Regards,
Mukul Gandhi

alt address : mukulgandhi@xxxxxxx

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.