[ https://issues.apache.org/jira/browse/XALANJ-2399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924654#action_12924654 ]
Ian Shields commented on XALANJ-2399: ------------------------------------- I am seeing the same issue with Xalan 2.7.1. We generate HTML from XML and run a check to confirm that internal anchors (<a href="#xxx" ...) exist and are unique. Some predefined anchor href targets will be generated by the stylesheet if certain elements exist in the XML, so we use literal keys for those particular ones and attribute values for most others, although the attributes may be different according to the particular element that supplies the name for the target. Both libxslt and Saxon 6.5.5 process this correctly. I found this problem when I attempted to merge several xsl:key definitions with different name so that they would use a single name. A simplified XML and XSL file are attached inside xslt-key-bug-xalan-2-7-1.zip The definitions are now <xsl:key name="target-names" match="//a...@name != ''] | //tit...@name != ''] | //capti...@name != ''] " use="@name"/> <xsl:key name="target-names" match="//headi...@refname != ''] | //tit...@refname != ''] | //capti...@refname != ''] " use="@refname"/> <xsl:key name="target-names" match="//target-content-file[1]|//target-content-page[not(//target-content-file)][1]" use=" 'download' "/> <xsl:key name="target-names" match="//resources[1] | //resource-list[not(//resources)][1]" use=" 'resources' "/> <xsl:key name="target-names" match="//dw-article| //dw-tutorial" use=" 'icomments' "/> Failing code is in the second xsl:when clause below. <xsl:variable name="target-key" select="key('target-names', $this-anchor)"/> <xsl:variable name="target-key-count" select="count(key('target-names', $this-anchor))"/> <xsl:choose> <xsl:when test="$target-key-count = 0"> <xsl:message> <xsl:value-of select="normalize-space(concat('No matching anchor was found for anchor <a href="', $this-href, '">'))" /> </xsl:message> </xsl:when> <xsl:when test="$target-key-count != 1"> <xsl:message> <xsl:value-of select="normalize-space(concat($target-key-count , ' possible targets for <a href="', $this-href, '> ">'))" /> </xsl:message> <xsl:for-each select="$target-key"> <xsl:message> <xsl:value-of select="concat( ' ', position(), ' ', local-name(), ' ', @type, ' ', normalize-space(substring(.,1,25)))" /> </xsl:message> </xsl:for-each> > key() on xsl:key with literal @use returns too many nodes > --------------------------------------------------------- > > Key: XALANJ-2399 > URL: https://issues.apache.org/jira/browse/XALANJ-2399 > Project: XalanJ2 > Issue Type: Bug > Affects Versions: 2.7 > Environment: Windows XP Pro x64; JRE 1.5.0_12 > Reporter: Deborah Pickett > > Using a literal* string value for @use in an xsl:key causes key() to return > too many nodes in the node-set for that key. > I define a key in a couple of places (same stylesheet or different, seems to > behave the same): > <xsl:key name="name" match="foo" use="'string'"/> > <xsl:key name="name" match="bar" use="..."/> > <xsl:key name="name" match="baz" use="..."/> > It does not seem to matter what the "..." are. > Calls to key('name', 'string') should give a node-set only of <foo> elements, > but I also get <bar> and <baz> elements, essentially every node that has a > presence in the "name" key. > Calls to key('name', 'never-seen-before-string') return an empty node-set. > * Or, it seems, an expression that can be optimized into a literal. This > makes the bug go away: > <xsl:key name="group" match="li...@type = 'concept']" > use="concat(substring(@type, 1, 1), 'oncept')"/> > but this still has the bug: > <xsl:key name="group" match="li...@type = 'concept']" > use="concat(substring(@type, 1, 0), 'concept')"/> > Small test case follows. > Source document: > <root> > <link href="somewhere.xml" type="concept"><linktext>C1</linktext></link> > <link href="somewhere.xml" type="concept"><linktext>C1</linktext></link> > <link href="somewhere.xml" type="concept" > importance="required"><linktext>C1 Prereq</linktext></link> > <link href="somewhere.xml" type="reference" > role="cousin"><linktext>R2</linktext></link> > <link href="somewhere.xml" type="reference" > role="sibling"><linktext>R1</linktext></link> > <link href="somewhere.xml" type="reference" > role="sibling"><linktext>R1</linktext></link> > <link href="somewhere.xml" type="task"><linktext>T1</linktext></link> > <link href="somewhere.xml" type="topic"><linktext>X1</linktext></link> > <link href="somewhere.xml"><linktext>X0</linktext></link> > <link href="somewhere.xml" type="unknown-thing" > role="sibling"><linktext>X2</linktext></link> > <link href="somewhere.xml" type="concept"><linktext>C1</linktext></link> > </root> > Stylesheet: > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > <xsl:key name="group" match="li...@type = 'concept']" use="'concept'"/> > <xsl:key name="group" match="li...@type = 'task']" use="'task'"/> > <xsl:key name="group" match="li...@type = 'reference']" > use="'reference'"/> > > <xsl:template match="/"> > <xsl:apply-templates select="key('group', 'concept')"/> > </xsl:template> > </xsl:stylesheet> > Expected output: > C1C1C1 PrereqC1 > Output with Xalan-J 2.7.0: > C1C1C1 PrereqR2R1R1T1C1 > $ java -cp c:/Program\ Files\ \(x86\)/Oxygen\ XML\ Editor\ 8.2/lib/xalan.jar > org.apache.xalan.xslt.EnvironmentCheck > #---- BEGIN writeEnvironmentReport($Revision: 1.29 $): Useful stuff found: > ---- > version.DOM.draftlevel=2.0fd > java.class.path=c:/Program Files (x86)/Oxygen XML Editor 8.2/lib/xalan.jar > version.JAXP=1.1 or higher > java.ext.dirs=C:\Program Files (x86)\Java\jre1.5.0_12\lib\ext > version.xerces2=Xerces-J 2.9.0 > version.xerces1=not-present > version.xalan2_2=Xalan Java 2.7.0 > version.xalan1=not-present > version.ant=not-present > java.version=1.5.0_12 > version.DOM=2.0 > version.crimson=not-present > sun.boot.class.path=C:\Program Files > (x86)\Java\jre1.5.0_12\lib\rt.jar;C:\Program Files > (x86)\Java\jre1.5.0_12\lib\i18n.jar;C:\Progr > am Files (x86)\Java\jre1.5.0_12\lib\sunrsasign.jar;C:\Program Files > (x86)\Java\jre1.5.0_12\lib\jsse.jar;C:\Program Files (x86)\Java\ > jre1.5.0_12\lib\jce.jar;C:\Program Files > (x86)\Java\jre1.5.0_12\lib\charsets.jar;C:\Program Files > (x86)\Java\jre1.5.0_12\classes > #---- BEGIN Listing XML-related jars in: foundclasses.java.class.path ---- > xalan.jar-path=c:\Program Files (x86)\Oxygen XML Editor 8.2\lib\xalan.jar > #----- END Listing XML-related jars in: foundclasses.java.class.path ----- > version.SAX=2.0 > version.xalan2x=Xalan Java 2.7.0 > #----- END writeEnvironmentReport: Useful properties found: ----- > # YAHOO! Your environment seems to be OK. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: xalan-dev-unsubscr...@xml.apache.org For additional commands, e-mail: xalan-dev-h...@xml.apache.org