[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Question about the key() function

Subject: RE: Question about the key() function
From: omprakash.v@xxxxxxxxxxxxx
Date: Sat, 14 May 2005 14:01:01 +0530
xsl loop remove duplicates
Hi,
    I get a "Out of memory" error when I run a transformation using the xml
and xsl given below using xalan.

Is this a xalan version issue. Iam using the xalan that gets shipped with
jaxp-1.3.

Also if I replace
<xsl:apply-templates select="key('x',addressbook/address/zip)" />

with
<xsl:copy-of select="key('x',addressbook/address/zip)" />

I get xml with root starting with addressbook though the key is supposed to
match only "address" nodes.
Also, I get an extra set of address nodes complete with child nodes with
duplicates outside addressbook but inside keyNode.

Can someone explain whats going on.

Cheers,
Omprakash.V









                                                                                                                   
                    "Michael Kay"                                                                                  
                    <mike@saxonic        To:     <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                                 
                    a.com>               cc:     (bcc: omprakash.v/Polaris)                                        
                                         Subject:     RE:  Question about the key() function                  
                    05/14/2005                                                                                     
                    03:08 AM                                                                                       
                    Please                                                                                         
                    respond to                                                                                     
                    xsl-list                                                                                       
                                                                                                                   
                                                                                                                   




Because there is a bug in your XSLT processor. The correct output is:

Saxon 8.4 from Saxonica
...
<?xml version="1.0" encoding="UTF-8"?>
<keyNode>
   <Name>1, Frisby, 48392</Name>
   <Name>10, Backstayge, 02718</Name>
   <Name>2, Attired, 00218</Name>
   <Name>20, Backstayge, 02718</Name>
   <Name>300, McGoon, 27318</Name>
   <Name>31, Reckonwith, 02930</Name>
</keyNode>

The key() function is specified to remove duplicates, it appears your
implementation is not doing so.

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: aspsa [mailto:aspsa@xxxxxxxxxxxxx]
> Sent: 13 May 2005 22:14
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Question about the key() function
>
> Hi, folks.
>
> Given this document...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <addressbook>
>  <address>
>   <name>
>    <title>Mr.</title>
>    <first-name>Chester Hasbrouck</first-name>
>    <last-name>Frisby</last-name>
>   </name>
>   <street>1234 Main Street</street>
>   <city>Sheboygan</city>
>   <state>WI</state>
>   <zip>48392</zip>
>   <id>1</id>
>  </address>
>  <address>
>   <name>
>    <first-name>Mary</first-name>
>    <last-name>Backstayge</last-name>
>   </name>
>   <street>283 First Avenue</street>
>   <city>Skunk Haven</city>
>   <state>MA</state>
>   <zip>02718</zip>
>   <id>10</id>
>  </address>
>  <address>
>   <name>
>    <title>Ms.</title>
>     <first-name>Natalie</first-name>
>     <last-name>Attired</last-name>
>   </name>
>   <street>707 Breitling Way</street>
>   <city>Winter Harbor</city>
>   <state>ME</state>
>   <zip>00218</zip>
>   <id>2</id>
>  </address>
>  <address>
>   <name>
>    <first-name>Harry</first-name>
>    <last-name>Backstayge</last-name>
>   </name>
>   <street>283 First Avenue</street>
>   <city>Skunk Haven</city>
>   <state>MA</state>
>   <zip>02718</zip>
>   <id>20</id>
>  </address>
>  <address>
>   <name>
>    <first-name>Mary</first-name>
>    <last-name>McGoon</last-name>
>   </name>
>   <street>103 Bryant Street</street>
>   <city>Boylston</city>
>   <state>VA</state>
>   <zip>27318</zip>
>   <id>300</id>
>  </address>
>  <address>
>   <name>
>    <title>Ms.</title>
>    <first-name>Amanda</first-name>
>    <last-name>Reckonwith</last-name>
>   </name>
>   <street>930-A Chestnut Street</street>
>   <city>Lynn</city>
>   <state>MA</state>
>   <zip>02930</zip>
>   <id>31</id>
>  </address>
> </addressbook>
>
> ...and this XSLT document...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:output method="xml" version="1.0" encoding="UTF-8"
> indent="yes"/>
>  <xsl:key name="x" match="address" use="zip"/>
>
>  <xsl:template match="/">
>   <keyNode>
>    <xsl:apply-templates select="key('x',addressbook/address/zip)" />
>   </keyNode>
>  </xsl:template>
>
>  <xsl:template match="address">
>   <Name>
>    <xsl:value-of select="id"/>
>    <xsl:text>, </xsl:text>
>    <xsl:value-of select="name/last-name"/>
>    <xsl:text>, </xsl:text>
>    <xsl:value-of select="zip"/>
>   </Name>
>  </xsl:template>
> </xsl:stylesheet>
>
> ...why does the output repeat nodes containing id values 10 and 20?
>
> <?xml version="1.0" encoding="UTF-8"?>
> <keyNode>
>  <Name>1, Frisby, 48392</Name>
>  <Name>10, Backstayge, 02718</Name>
>  <Name>10, Backstayge, 02718</Name>
>  <Name>2, Attired, 00218</Name>
>  <Name>20, Backstayge, 02718</Name>
>  <Name>20, Backstayge, 02718</Name>
>  <Name>300, McGoon, 27318</Name>
>  <Name>31, Reckonwith, 02930</Name>
> </keyNode>
>
>
> Respectfully,
>
> ASP






This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.