Re: bug(?) when reusing a xsl:key across multiple templates
Mukul Gandhi <[email protected]> Wed, 16 Oct 2013 15:05:46 +0530
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Message-ID | <CABuuzNNSJ-+m=DMaxn4mXwX_WJmoYSpYuK+DQeSfvRswTvhiCQ@mail.gmail.com> |
--089e0122893632af7f04e8d86e62 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable I feel this is not a bug. My reading of XSLT 1.0 spec says, that a xsl:key declaration (or a set of them) within a stylesheet are applicable only to one document. Two different nodesets (constructed from a RTF) are conceptually two different documents, therefore as per above notion they cannot share xsl:key declarations. On Wed, Oct 16, 2013 at 12:18 AM, Hall, Kurt (Truven Health) < [email protected]> wrote: > I suspect that I have found a bug pertaining to multiple key() function > calls that share a common xsl:key but occur in different templates. Both > key() calls are operating on results-tree-fragments that I=92ve turned in= to > nodesets with the xalan:nodeset() extension.**** > > ** ** > > When the calls are in different templates the second occurance of key() > doesn=92t return any results. If I combine template1 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 reusi= ng > them.**** > > ** ** > > I=92m 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/Transform" 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:= message>**** > > <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= -of > 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:= message>**** > > <xsl:variable > name=3D"rtf2"><N4>4</N4><N5>5</N5><N6>6</N6></xsl:variable>**** > > <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:val= ue-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=92m 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. **** > > ** ** > --=20 Regards, Mukul Gandhi --089e0122893632af7f04e8d86e62 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div><div>I feel this is not a bug. My reading of XSLT 1.0= spec says, that a xsl:key declaration (or a set of them) within a styleshe= et are applicable only to one document.<br><br></div>Two different nodesets= (constructed from a RTF) are conceptually two different documents, therefo= re as per above notion they cannot share xsl:key declarations.<br> </div><div><div><div><div><div class=3D"gmail_extra"><br><div class=3D"gmai= l_quote">On Wed, Oct 16, 2013 at 12:18 AM, Hall, Kurt (Truven Health) <span= dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_b= lank">[email protected]</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left:1px solid rgb(204,204,204);padding-left:1ex"> <div link=3D"blue" vlink=3D"purple" lang=3D"EN-US"> <div> <p class=3D"">I suspect that I have found a bug pertaining to multiple key(= ) function calls that share a common xsl:key but occur in different templat= es.=A0 Both key() calls are operating on results-tree-fragments that I=92ve= turned into nodesets with the xalan:nodeset() extension.<u></u><u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D"">When the calls are in different templates the second occuranc= e of key() doesn=92t return any results.=A0 If I combine template1 and temp= late2 into a single template then I get correct results for both key() call= s.=A0 I have worked around the issue by cloning the xsl:key (key2) and no longer reusing them.<u></u><u><= /u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D"">I=92m using Xalan 2.7.1. <u></u><u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D""><b>Results<u></u><u></u></b></p> <p class=3D"">=3D=3D=3D=3D=3D=3D Template 1 =3D=3D=3D=3D=3D=3D<u></u><u></u= ></p> <p class=3D"">count(tree1)=3D2<u></u><u></u></p> <p class=3D"">N1=3D1<u></u><u></u></p> <p class=3D"">N2=3D2<u></u><u></u></p> <p class=3D"">N3=3D3<u></u><u></u></p> <p class=3D"">=3D=3D=3D=3D=3D=3D Template 2 =3D=3D=3D=3D=3D=3D<u></u><u></u= ></p> <p class=3D"">count(tree2)=3D3<u></u><u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D"">Test Code:<u></u><u></u></p> <p class=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=3D<u></u><u></u></p> <p class=3D""><span style=3D"font-family:"Courier New""><?xml = version=3D"1.0"=A0 encoding =3D "ISO-8859-1"?><u></u= ><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""><xsl:s= tylesheet version=3D"1.0" xmlns:xsl=3D"<a href=3D"http://www= .w3.org/1999/XSL/Transform" target=3D"_blank">http://www.w3.org/1999/XSL/Tr= ansform</a>" xmlns:xalan=3D"<a href=3D"http://xml.apache.org/xala= n" target=3D"_blank">http://xml.apache.org/xalan</a>" exclude-result-p= refixes=3D"xalan"> <u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""><u></u>= =A0<u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 <x= sl:key name=3D"key1" match=3D"*" use=3D"text()&quo= t;/><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 <x= sl:key name=3D"key2" match=3D"*" use=3D"text()&quo= t;/><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""><u></u>= =A0<u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 <x= sl:template match=3D"/"><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:call-template name=3D"template1"/><u></u><u></u= ></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:call-template name=3D"template2"/><u></u><u></u= ></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:call-template name=3D"template3"/><u></u><u></u= ></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 </= xsl:template><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""><u></u>= =A0<u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 <x= sl:template name=3D"template1"><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:message>=3D=3D=3D=3D=3D=3D Template 1 =3D=3D=3D=3D=3D=3D&= lt;/xsl:message><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:variable name=3D"rtf1"><N1>1</N1>&l= t;N2>2</N2></xsl:variable><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:variable name=3D"tree1" select=3D"xalan:nodes= et( $rtf1)"/><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:message>count(tree1)=3D<xsl:value-of select=3D"co= unt( $tree1/*)"/></xsl:message><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:variable name=3D"uniqNodes" select=3D"$tree1/= *[generate-id() =3D generate-id( key( 'key1', text()))]"/><= u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:for-each select=3D"$uniqNodes"><u></u><u></u></= span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0=A0=A0 <xsl:message><xsl:value-of select=3D"local-name(= )"/>=3D<xsl:value-of select=3D"text()"/></xsl:me= ssage><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 </xsl:for-each><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 </= xsl:template><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""><u></u>= =A0<u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 <x= sl:template name=3D"template2"><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:message>=3D=3D=3D=3D=3D=3D Template 2 =3D=3D=3D=3D=3D=3D&= lt;/xsl:message><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:variable name=3D"rtf2"><N4>4</N4>&l= t;N5>5</N5><N6>6</N6></xsl:variable><u></u><u></= u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:variable name=3D"tree2" select=3D"xalan:nodes= et( $rtf2)"/><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:message>count(tree2)=3D<xsl:value-of select=3D"co= unt( $tree2/*)"/></xsl:message><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <!-- ************=A0 CHANGE FOLLOWING FROM key1 to key2 *********= **** --><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:variable name=3D"uniqNodes" select=3D"$tree2/= *[generate-id() =3D generate-id( key( 'key1', text()))]"/><= u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <!-- ************************************************************= ** --><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 <xsl:for-each select=3D"$uniqNodes"><u></u><u></u></= span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0=A0=A0=A0=A0 <xsl:message><xsl:value-of select=3D"local= -name()"/>=3D<xsl:value-of select=3D"text()"/></= xsl:message><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0=A0=A0= =A0=A0 </xsl:for-each><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New"">=A0 </= xsl:template><u></u><u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""><u></u>= =A0<u></u></span></p> <p class=3D""><span style=3D"font-family:"Courier New""></xsl:= stylesheet><u></u><u></u></span></p> <p class=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=3D<u></u><u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D"">Thanks for any help,<u></u><u></u></p> <p class=3D"">-kurt<u></u><u></u></p> <p class=3D"">(This is my first post to the user-group so forgive me if I= =92m not following proper protocol)<u></u><u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D""><u></u>=A0<u></u></p> <p class=3D""><span style=3D"font-size:9pt;font-family:"Arial",&q= uot;sans-serif";color:rgb(37,40,42)"><br> <b>Kurt Hall</b><br> Principal Engineer<u></u><u></u></span></p> <p class=3D"" style=3D"margin-right:0in;margin-bottom:9pt;margin-left:0in"> <b><span style=3D"font-size:9pt;font-family:"Arial","sans-se= rif";color:rgb(0,114,206)">Truven Health Analytics<u></u><u></u></span= ></b></p> <p class=3D""><span style=3D"font-size:9pt;font-family:"Arial",&q= uot;sans-serif";color:rgb(37,40,42)">Phone: </span><span style=3D"font-size:9pt;font-family:"Arial","san= s-serif";color:rgb(102,102,102)">303-486-9161</span><span style=3D"fon= t-size:9pt;font-family:"Arial","sans-serif";color:rgb(3= 7,40,42)"><u></u><u></u></span></p> <p class=3D"" style=3D"margin-right:0in;margin-bottom:9pt;margin-left:0in"> <span style=3D"font-size:9pt;font-family:"Arial","sans-serif= ";color:rgb(0,114,206)"><a href=3D"mailto:[email protected]" = target=3D"_blank">[email protected]</a><br> <a href=3D"http://truvenhealth.com" target=3D"_blank">truvenhealth.com</a><= u></u><u></u></span></p> <p class=3D""><span style=3D"font-size:9pt;font-family:"Arial",&q= uot;sans-serif";color:rgb(37,40,42)">The Healthcare Business of Thomso= n Reuters is now <br> Truven Health Analytics. <u></u><u></u></span></p> <p class=3D""><u></u>=A0<u></u></p> </div> </div> </blockquote></div><br><br clear=3D"all"><br>-- <br>Regards,<br>Mukul Gandh= i </div></div></div></div></div></div> --089e0122893632af7f04e8d86e62--