We use Altova Stylevision which produces XSLT 2.0 files. We use Saxon 9 for Java to execute these XSLT files. This has been working well for a few years, alas none of us actually understand XSLT.
Now we have the error:
Error at /xsl:stylesheet/xsl:function[9]
XPDY0002: Axis step child::element(item, xs:anyType) cannot be used here:
the context item is undefined
The 9th function is:
<xsl:function name="sps:GoogleChartDataSourceUnitCount" as="xs:string">
<xsl:sequence select="concat(string-join(item/string(if ( number($XML/report/calculation-data[@data-source-name = $DataSourceParent]/item/variable[@name='unit_count']/@value) < 0 ) then 0 else round-half-to-even(number(variable[@name='unit_count']/@value),2)),','),'&chxl=0:|',string-join(item/variable[@name='month']/@value,'|'),'|2:||Min&chds=0,',string(round-half-to-even( max(item/(number(variable[@name='unit_count']/@value)))+1 , 0 )),'&chxr=1,0,',string(round-half-to-even( max(item/(number(variable[@name='unit_count']/@value)))+1 , 0 )))"/>
</xsl:function>
Does anyone have any idea what's going on?
The problem is that the function uses path expressions like item
which need a context item as the specification mandates "Within the body of a stylesheet function, the focus is initially undefined; this means that any attempt to reference the context item, context position, or context size is a non-recoverable dynamic error. [XPDY0002]". So the function needs to have a parameter that passes in the node or sequence of nodes to which the path should be applied e.g.
<xsl:function name="sps:GoogleChartDataSourceUnitCount" as="xs:string">
<xsl:param name="nodes"/>
<xsl:sequence select="concat(string-join($nodes/item/string(...)))"/>
</xsl:function>
and then needs to be called with e.g. sps:GoogleChartDataSourceUnitCount(.)
.
If the stylesheet is generated by some tool from Altova you might want to enquire in the Altova forums whether this is a known issue and whether a fix is available.