|
[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








