[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] xsl:key only checks first child, need to check all


Subject: Re: [xsl] xsl:key only checks first child, need to check all
From: Patrick Warren <warr0120@xxxxxxx>
Date: Fri, 04 Nov 2005 21:09:36 -0600

Alright, I've trimmed down the xml and xsl. The problem again is that I can't get rid of duplicates using the Muench method, and I have no idea how else to do it. I repeat my question at the end.

Here's the xml:

<sources>
<source>
<authors>
<author><name>Deloria, Ella C.</name></author>
<author><name>Rice, Julian</name></author>
</authors> <topics>
<topic>texts</topic>
<topic>culture</topic>
</topics>
</source>
<source>
<authors>
<author><name>Deloria, Ella C.</name></author>
<author><name>Rice, Julian</name></author>
</authors> <topics>
<topic>texts</topic>
<topic>culture</topic>
</topics>
</source>


</sources>

Here's the xsl:

<xsl:key name = "topics" match = " topic " use = " . " />
<xsl:key name = "authorsByTopicAndAuthor" match = " author / name " use = " concat ( .. / .. / .. / topics / topic , . ) " />


<xsl:template match = "/" >
<html>
<xsl:for-each select = "// sources / source / topics / topic [ count ( . | key ( 'topics' , . ) [ 1 ] ) = 1 ] " >
<xsl:sort select = " . " />
<xsl:variable name = "currentTopic" select = " . " />


                   <xsl:value-of select = " $currentTopic " />
                   <br />

<xsl:for-each select = " // sources / source [ topics / topic = $currentTopic ] / authors / author / name [ count ( . | key ( 'authorsByTopicAndAuthor' , concat ( $currentTopic , . ) ) [ 1 ] ) = 1 ] " >
<xsl:sort select = " . " />
<xsl:variable name = "currentAuthor" select = "." />
<xsl:text>-----</xsl:text>
<xsl:value-of select = " $currentAuthor " />
<br />
</xsl:for-each>


               </xsl:for-each>
       </html>
   </xsl:template>


Here's the output in firefox:


culture
-----Deloria, Ella C.
-----Deloria, Ella C.
-----Rice, Julian
-----Rice, Julian
texts
-----Deloria, Ella C.
-----Rice, Julian


Here's the output I want:


culture
-----Deloria, Ella C.
-----Rice, Julian
texts
-----Deloria, Ella C.
-----Rice, Julian

The key 'authorsByTopicAndAuthor' is only checking ../../../topics/topic[1] but I want it to match each topic([2], [3]. etc.), so any author of a source with a topic equal to the currentTopic is only listed once. Right now it's only checking to see if the first topics/topic matches currentTopic. The Muench method seems to work fine to any depth if the relationship (author-topic in this case) is one-to-one or one-to-many, but not if it's many-to-many (a source can have multiple authors and multiple topics). How can I deal with this problem?

Thanks again,
Patrick


Current Thread
Keywords
xml