[ https://issues.apache.org/jira/browse/XALANJ-2799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17936222#comment-17936222 ]
Mukul Gandhi commented on XALANJ-2799: -------------------------------------- [~martin.honnen] It'll be helpful I think, if we have an XML Schema document for an XML input document that you've shared within this bug report. I'm personally not a great expert on understanding in detail the XSLT 3.0 spec for xsl:key instruction and key(..) function. I think, this is quite different (although, similar in intent) than the corresponding definitions provided by XSLT 1.0 and XPath 1.0 specs. I've worked earlier using XSL 1 xsl:key instruction and key(..) function. Hoping to find time to write a better fix for this bug report. > 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: dev-unsubscr...@xalan.apache.org For additional commands, e-mail: dev-h...@xalan.apache.org