xsl-list
[Top] [All Lists]

Re: Multiple matches against keys?

2004-08-30 01:59:29


So it looks like my key definition is no longer picking up "call" as a
valid key item. I'm actually not sure whether I'm using the <xsl:key>
tag correctly here -- will it match and index a single <task> node
multiple times if it contains multiple tags?


I think your problem is that you are passing a nodeset to the key call so that 
it retruns results from different 'context' sets. This means you can't use 
the count(.|key(...)[1])=1 trick to isolate the first from a particular 
'context'.  One way to fix is is to loop both over the 'task' and then the 
child 'context' elements and apply the same test. Something like this should 
work,

<xsl:for-each select="/tasks/task">
 <xsl:sort select="subject"/>
 <xsl:for-each select="context">
  <xsl:if test="count((..|key('tasks-by-context',.)[1]))=1">
   <li>
    CONTEXT: <xsl:value-of select="."/>: (<xsl:value-of
        select="count(key('tasks-by-context',.))"/> tasks)
   </li>
   <ul>
    <xsl:for-each select="key('tasks-by-context', .)">
     <li>
       Task : <xsl:value-of select="subject"/>
     </li>
    </xsl:for-each>
   </ul>
  </xsl:if>
 </xsl:for-each>
</xsl:for-each>

Kev.



<Prev in Thread] Current Thread [Next in Thread>