[
https://issues.apache.org/jira/browse/XALANJ-2799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17936201#comment-17936201
]
Vladimir Sitnikov commented on XALANJ-2799:
-------------------------------------------
Frankly, the added `catch (ClassCastException e)` looks weird (see
https://github.com/apache/xalan-java/commit/7a6567ae73db32093ccab202dc98c01ef20ea622#diff-9209e744c2c6b39d67c6d5354e75e34813bb82cfad8eb854f5f3252cdd6ab384R4418-R4420).
It would be better to avoid throwing ClassCastException in the first place
rather than try catching it. At the same time, the message might be different
in different JVMs, so the fix is not reliable. At the same time it would be
nice to have tests added along with the fix
> java.lang.ClassCastException: org.apache.xpath.objects.XString cannot be cast
> to java.lang.String when using XSLT key function on the right side of step
> operator /
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: XALANJ-2799
> URL: https://issues.apache.org/jira/browse/XALANJ-2799
> Project: XalanJ2
> Issue Type: Bug
> Security Level: No security risk; visible to anyone(Ordinary problems in
> Xalan projects. Anybody can view the issue.)
> Components: transformation, Xalan, Xalan-CmdLine
> Affects Versions: The Latest Development Code
> Environment: Java 8, Windows 11
> Reporter: Martin Honnen
> Priority: Major
> Attachments: cars.xml, key-fn-call-in-last-step-test1.xsl
>
>
> Working with the latest XSLT 3.0 branch of Apache Xalan, I get an exception
> `java.lang.ClassCastException: org.apache.xpath.objects.XString cannot be
> cast to java.lang.String` when trying to use the XSLT `key` function on the
> right side of the "path" operator `/` e.g. `key('car-by-color', 'red') /
> key('lot-for-car', @vin)`.
> I would expect the right side of the / to be evaluated for each node selected
> by the expression on the left side of /, without giving any errors. This is
> an established XPath 2 and XSLT 2 coding pattern.
> The full code
> {code:xml}
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="3.0"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> exclude-result-prefixes="xs">
> <xsl:output method="xml" indent="yes"/>
> <xsl:key name="car-by-color" match="cars/car" use="@color"/>
>
> <xsl:key name="lot-for-car" match="lot" use="car/@vin"/>
>
> <xsl:template match="lot">
> <lot id="{@id}"/>
> </xsl:template>
>
> <xsl:template match="/">
> <set>
> <problem>
> <question>Which lots have red cars?</question>
> <answer>
> <xsl:apply-templates select="key('car-by-color', 'red') /
> key('lot-for-car', @vin)"/>
> </answer>
> </problem>
> </set>
> </xsl:template>
> </xsl:stylesheet>
> {code}
> Sample XML input is e.g.
> {code:xml}
> <dir>
> <cars>
> <car vin="101" color="red"/>
> <car vin="102" color="green"/>
> <car vin="103" color="red"/>
> <car vin="104" color="red"/>
> </cars>
> <lots>
> <lot id="L">
> <car vin="101"/>
> <car vin="103"/>
> </lot>
> <lot id="M">
> <car vin="102"/>
> </lot>
> <lot id="N">
> <car vin="104"/>
> </lot>
> </lots>
> </dir>
> {code}
> Full error output:
> {code}
> (Position des Fehlers unbekannt)java.lang.ClassCastException:
> org.apache.xpath.objects.XString cannot be cast to java.lang.String
> (Position des Fehlers unbekannt)XSLT-Fehler
> (javax.xml.transform.TransformerException): Keine Verarbeitungsanweisung f³r
> xml-stylesheet gefunden in
> ..\..\OneDrive\Documents\xslt\blog-xslt-3-by-example\xalan-xslt3-tests\cars.xml.
> Exception in thread "main" java.lang.RuntimeException: Keine
> Verarbeitungsanweisung für xml-stylesheet gefunden in
> ..\..\OneDrive\Documents\xslt\blog-xslt-3-by-example\xalan-xslt3-tests\cars.xml.
> at org.apache.xalan.xslt.Process.doExit(Process.java:1176)
> at org.apache.xalan.xslt.Process.main(Process.java:1149)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]