You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Phil Friedman <pf...@terralink.com> on 2004/11/10 16:23:25 UTC

stumped by key not working

I have a XML input file, like so:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT ... >
<HISTORY ... HISTORY_ID="18291" PREV_HISTORY_ID="19072" ... >
...
</HISTORY>
<HISTORY ... HISTORY_ID="19073" PREV_HISTORY_ID="19071" ... >
...
</HISTORY>
<HISTORY ... HISTORY_ID="19072" PREV_HISTORY_ID="19036" ... >
...
</HISTORY>
<HISTORY ... HISTORY_ID="19071" PREV_HISTORY_ID="19023" ... >
...
</HISTORY>
...
</ROOT>

And a style sheet , like so:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:sql="org.apache.xalan.lib.sql.XConnection" extension-element-prefixes="sql" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan">
...
<xsl:variable name="ROOT" select="/"/>
<xsl:key name="HISTORY_HISTORY_ID" match="/ROOT/HISTORY" use="@HISTORY_ID"/>
...
		<xsl:variable name="PREV_HISTORY">
		  <xsl:copy-of select="xalan:nodeset($ROOT)/ROOT/HISTORY[ current()/@PREV_HISTORY_ID= @HISTORY_ID]"/>
		</xsl:variable>

		<xsl:variable name="PREV_HISTORY_BYKEY">
		  <xsl:copy-of select="key( 'HISTORY_HISTORY_ID', @PREV_HISTORY_ID)"/>
		</xsl:variable>
...
</xsl:stylesheet>

My question: Why aren't the variables PREV_HISTORY and PREV_HISTORY_BYKEY equivalent? PREV_HISTORY works as expected, but PREV_HISTORY_BYKEY usually returns nothing. Is my code incorrect or might this be a Xalan bug? Several other keys seem to be returning the expected results. Any ideas would be appreciated. Thanks.

I'm using Xalan 2.6.0 like so:

C:\Xvsn\3X>"C:\Program Files\Java\j2re1.4.2_05\bin\java" -Xbootclasspath/p:"C:\Shared\xalan-j_2_6_0.2-01-NNN\build\xalan.jar";"C:\Shared\xalan-j_2_6_0.2-01-NNN\bin\xercesImpl.jar";"C:\Shared\xalan-j_2_6_0.2-01-NNN\bin\xml-apis.jar" -cp "C:\Program Files\Sybase\Shared8.0.2.4398\jConnect-5_5\classes\jconn2.jar";"C:\Program Files\NetDirect\JDataConnect2.21.004\JARs\JData2_0.jar" -Xmx512m org.apache.xalan.xslt.Process -xsl TtyMap.xsl -in in.xml -out out.txi

Regards, Phil Friedman



Re: stumped by key not working

Posted by Christine Li <jy...@ca.ibm.com>.
Hi, Phil

I don't think it is a Xalan bug and you are right that the two variables 
PREV_HISTORY and PREV_HISTORY_BYKEY should produce equivalent results. It 
is better to provide a fully working stylesheet to identify the problem.

Thanks,

Christine Li
XSLT Development
IBM Toronto Lab
Tel: (905)413-2601
Email: jycli@ca.ibm.com



Phil Friedman <pf...@terralink.com> 
11/10/2004 10:23 AM
Please respond to
pfriedma


To

cc
xalan-j-users <xa...@xml.apache.org>
Subject
stumped by key not working






I have a XML input file, like so:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT ... >
<HISTORY ... HISTORY_ID="18291" PREV_HISTORY_ID="19072" ... >
...
</HISTORY>
<HISTORY ... HISTORY_ID="19073" PREV_HISTORY_ID="19071" ... >
...
</HISTORY>
<HISTORY ... HISTORY_ID="19072" PREV_HISTORY_ID="19036" ... >
...
</HISTORY>
<HISTORY ... HISTORY_ID="19071" PREV_HISTORY_ID="19023" ... >
...
</HISTORY>
...
</ROOT>

And a style sheet , like so:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0" xmlns:sql="org.apache.xalan.lib.sql.XConnection" 
extension-element-prefixes="sql" xmlns:xalan="http://xml.apache.org/xalan" 
exclude-result-prefixes="xalan">
...
<xsl:variable name="ROOT" select="/"/>
<xsl:key name="HISTORY_HISTORY_ID" match="/ROOT/HISTORY" 
use="@HISTORY_ID"/>
...
                                 <xsl:variable name="PREV_HISTORY">
                                   <xsl:copy-of 
select="xalan:nodeset($ROOT)/ROOT/HISTORY[ current()/@PREV_HISTORY_ID= 
@HISTORY_ID]"/>
                                 </xsl:variable>

                                 <xsl:variable name="PREV_HISTORY_BYKEY">
                                   <xsl:copy-of select="key( 
'HISTORY_HISTORY_ID', @PREV_HISTORY_ID)"/>
                                 </xsl:variable>
...
</xsl:stylesheet>

My question: Why aren't the variables PREV_HISTORY and PREV_HISTORY_BYKEY 
equivalent? PREV_HISTORY works as expected, but PREV_HISTORY_BYKEY usually 
returns nothing. Is my code incorrect or might this be a Xalan bug? 
Several other keys seem to be returning the expected results. Any ideas 
would be appreciated. Thanks.

I'm using Xalan 2.6.0 like so:

C:\Xvsn\3X>"C:\Program Files\Java\j2re1.4.2_05\bin\java" 
-Xbootclasspath/p:"C:\Shared\xalan-j_2_6_0.2-01-NNN\build\xalan.jar";"C:\Shared\xalan-j_2_6_0.2-01-NNN\bin\xercesImpl.jar";"C:\Shared\xalan-j_2_6_0.2-01-NNN\bin\xml-apis.jar" 
-cp "C:\Program 
Files\Sybase\Shared8.0.2.4398\jConnect-5_5\classes\jconn2.jar";"C:\Program 
Files\NetDirect\JDataConnect2.21.004\JARs\JData2_0.jar" -Xmx512m 
org.apache.xalan.xslt.Process -xsl TtyMap.xsl -in in.xml -out out.txi

Regards, Phil Friedman