bug(?) when reusing a xsl:key across multiple templates
"Hall, Kurt (Truven Health)" <[email protected]> Tue, 15 Oct 2013 18:48:03 +0000
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Message-ID | <5382f7a88aed42998d170a118d7eadaf@BY2PR07MB089.namprd07.prod.outlook.com> |
--_000_5382f7a88aed42998d170a118d7eadafBY2PR07MB089namprd07pro_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
I suspect that I have found a bug pertaining to multiple key() function cal=
ls that share a common xsl:key but occur in different templates. Both key(=
) calls are operating on results-tree-fragments that I've turned into nodes=
ets with the xalan:nodeset() extension.
When the calls are in different templates the second occurance of key() doe=
sn't return any results. If I combine template1 and template2 into a singl=
e template then I get correct results for both key() calls. I have worked =
around the issue by cloning the xsl:key (key2) and no longer reusing them.
I'm using Xalan 2.7.1.
Results
=3D=3D=3D=3D=3D=3D Template 1 =3D=3D=3D=3D=3D=3D
count(tree1)=3D2
N1=3D1
N2=3D2
N3=3D3
=3D=3D=3D=3D=3D=3D Template 2 =3D=3D=3D=3D=3D=3D
count(tree2)=3D3
Test Code:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
<?xml version=3D"1.0" encoding =3D "ISO-8859-1"?>
<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tra=
nsform" xmlns:xalan=3D"http://xml.apache.org/xalan" exclude-result-prefixes=
=3D"xalan">
<xsl:key name=3D"key1" match=3D"*" use=3D"text()"/>
<xsl:key name=3D"key2" match=3D"*" use=3D"text()"/>
<xsl:template match=3D"/">
<xsl:call-template name=3D"template1"/>
<xsl:call-template name=3D"template2"/>
<xsl:call-template name=3D"template3"/>
</xsl:template>
<xsl:template name=3D"template1">
<xsl:message>=3D=3D=3D=3D=3D=3D Template 1 =3D=3D=3D=3D=3D=3D</xsl:me=
ssage>
<xsl:variable name=3D"rtf1"><N1>1</N1><N2>2</N2></xsl:variable>
<xsl:variable name=3D"tree1" select=3D"xalan:nodeset( $rtf1)"/>
<xsl:message>count(tree1)=3D<xsl:value-of select=3D"count( $tree1/*)"=
/></xsl:message>
<xsl:variable name=3D"uniqNodes" select=3D"$tree1/*[generate-id() =3D=
generate-id( key( 'key1', text()))]"/>
<xsl:for-each select=3D"$uniqNodes">
<xsl:message><xsl:value-of select=3D"local-name()"/>=3D<xsl:value-o=
f select=3D"text()"/></xsl:message>
</xsl:for-each>
</xsl:template>
<xsl:template name=3D"template2">
<xsl:message>=3D=3D=3D=3D=3D=3D Template 2 =3D=3D=3D=3D=3D=3D</xsl:me=
ssage>
<xsl:variable name=3D"rtf2"><N4>4</N4><N5>5</N5><N6>6</N6></xsl:varia=
ble>
<xsl:variable name=3D"tree2" select=3D"xalan:nodeset( $rtf2)"/>
<xsl:message>count(tree2)=3D<xsl:value-of select=3D"count( $tree2/*)"=
/></xsl:message>
<!-- ************ CHANGE FOLLOWING FROM key1 to key2 ************* -=
->
<xsl:variable name=3D"uniqNodes" select=3D"$tree2/*[generate-id() =3D=
generate-id( key( 'key1', text()))]"/>
<!-- ************************************************************** -=
->
<xsl:for-each select=3D"$uniqNodes">
<xsl:message><xsl:value-of select=3D"local-name()"/>=3D<xsl:value=
-of select=3D"text()"/></xsl:message>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Thanks for any help,
-kurt
(This is my first post to the user-group so forgive me if I'm not following=
proper protocol)
Kurt Hall
Principal Engineer
Truven Health Analytics
Phone: 303-486-9161
[email protected]
truvenhealth.com
The Healthcare Business of Thomson Reuters is now
Truven Health Analytics.
--_000_5382f7a88aed42998d170a118d7eadafBY2PR07MB089namprd07pro_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:x=3D"urn:schemas-microsoft-com:office:excel" xmlns:m=3D"http://schema=
s.microsoft.com/office/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html=
40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">I suspect that I have found a bug pertaining to mult=
iple key() function calls that share a common xsl:key but occur in differen=
t templates. Both key() calls are operating on results-tree-fragments=
that I’ve turned into nodesets with the
xalan:nodeset() extension.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">When the calls are in different templates the second=
occurance of key() doesn’t return any results. If I combine te=
mplate1 and template2 into a single template then I get correct results for=
both key() calls. I have worked around the
issue by cloning the xsl:key (key2) and no longer reusing them.<o:p></o:p>=
</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">I’m using Xalan 2.7.1. <o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><b>Results<o:p></o:p></b></p>
<p class=3D"MsoNormal">=3D=3D=3D=3D=3D=3D Template 1 =3D=3D=3D=3D=3D=3D<o:p=
></o:p></p>
<p class=3D"MsoNormal">count(tree1)=3D2<o:p></o:p></p>
<p class=3D"MsoNormal">N1=3D1<o:p></o:p></p>
<p class=3D"MsoNormal">N2=3D2<o:p></o:p></p>
<p class=3D"MsoNormal">N3=3D3<o:p></o:p></p>
<p class=3D"MsoNormal">=3D=3D=3D=3D=3D=3D Template 2 =3D=3D=3D=3D=3D=3D<o:p=
></o:p></p>
<p class=3D"MsoNormal">count(tree2)=3D3<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Test Code:<o:p></o:p></p>
<p class=3D"MsoNormal">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<o:p></o:p><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<?xml version=3D"1.0" encoding =3D "ISO-8859-1"=
;?><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w=
3.org/1999/XSL/Transform" xmlns:xalan=3D"http://xml.apache.org/xa=
lan" exclude-result-prefixes=3D"xalan">
<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:key name=3D"key1" match=3D"*" use=3D&quo=
t;text()"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:key name=3D"key2" match=3D"*" use=3D&quo=
t;text()"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:template match=3D"/"><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:call-template name=3D"template1=
"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:call-template name=3D"template2=
"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:call-template name=3D"template3=
"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
</xsl:template><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:template name=3D"template1"><o:p></o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:message>=3D=3D=3D=3D=3D=3D Templa=
te 1 =3D=3D=3D=3D=3D=3D</xsl:message><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:variable name=3D"rtf1">=
<N1>1</N1><N2>2</N2></xsl:variable><o:p></o:p=
></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:variable name=3D"tree1" se=
lect=3D"xalan:nodeset( $rtf1)"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:message>count(tree1)=3D<xsl:va=
lue-of select=3D"count( $tree1/*)"/></xsl:message><o:p><=
/o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:variable name=3D"uniqNodes"=
; select=3D"$tree1/*[generate-id() =3D generate-id( key( 'key1', text(=
)))]"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:for-each select=3D"$uniqNodes&q=
uot;><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:message><xsl:value=
-of select=3D"local-name()"/>=3D<xsl:value-of select=3D&quo=
t;text()"/></xsl:message><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
</xsl:for-each><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
</xsl:template><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:template name=3D"template2"><o:p></o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:message>=3D=3D=3D=3D=3D=3D Templa=
te 2 =3D=3D=3D=3D=3D=3D</xsl:message><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:variable name=3D"rtf2">=
<N4>4</N4><N5>5</N5><N6>6</N6></xsl:=
variable><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:variable name=3D"tree2" se=
lect=3D"xalan:nodeset( $rtf2)"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:message>count(tree2)=3D<xsl:va=
lue-of select=3D"count( $tree2/*)"/></xsl:message><o:p><=
/o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<!-- ************ CHANGE FOLLOWING =
FROM key1 to key2 ************* --><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:variable name=3D"uniqNodes"=
; select=3D"$tree2/*[generate-id() =3D generate-id( key( 'key1', text(=
)))]"/><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<!-- ************************************=
************************** --><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:for-each select=3D"$uniqNodes&q=
uot;><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<xsl:message>&=
lt;xsl:value-of select=3D"local-name()"/>=3D<xsl:value-of s=
elect=3D"text()"/></xsl:message><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
</xsl:for-each><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
</xsl:template><o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
<o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:"Courier New"">=
</xsl:stylesheet><o:p></o:p></span></p>
<p class=3D"MsoNormal">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<o:p></o:p><=
/p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Thanks for any help,<o:p></o:p></p>
<p class=3D"MsoNormal">-kurt<o:p></o:p></p>
<p class=3D"MsoNormal">(This is my first post to the user-group so forgive =
me if I’m not following proper protocol)<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><span style=3D"font-size:9.0pt;font-family:"Ari=
al","sans-serif";color:#25282A"><br>
<b>Kurt Hall</b><br>
Principal Engineer<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"mso-margin-top-alt:9.0pt;margin-right:0in;m=
argin-bottom:9.0pt;margin-left:0in">
<b><span style=3D"font-size:9.0pt;font-family:"Arial","sans-=
serif";color:#0072CE">Truven Health Analytics<o:p></o:p></span></b></p=
>
<p class=3D"MsoNormal" style=3D"mso-margin-top-alt:auto;mso-margin-bottom-a=
lt:auto"><span style=3D"font-size:9.0pt;font-family:"Arial","=
;sans-serif";color:#25282A">Phone:
</span><span style=3D"font-size:9.0pt;font-family:"Arial","s=
ans-serif";color:#666666">303-486-9161</span><span style=3D"font-size:=
9.0pt;font-family:"Arial","sans-serif";color:#25282A"><=
o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"mso-margin-top-alt:9.0pt;margin-right:0in;m=
argin-bottom:9.0pt;margin-left:0in">
<span style=3D"font-size:9.0pt;font-family:"Arial","sans-ser=
if";color:#0072CE">[email protected]<br>
truvenhealth.com<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:9.0pt;font-family:"Ari=
al","sans-serif";color:#25282A">The Healthcare Business of T=
homson Reuters is now
<br>
Truven Health Analytics. <o:p></o:p></span></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>
--_000_5382f7a88aed42998d170a118d7eadafBY2PR07MB089namprd07pro_--