This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RE: (Keys on multiple element types)


Hi Ahmad,

> OK, so if I do
>
> <xsl:key name="rows" match="FILES/*"
>          use="concat(name(), '+', name)" />

So the key values are:

  'RECORDA+Fred'
  'RECORDA+Fred'
  'RECORDB+Fred'
  'RECORDC+Harry'

> <xsl:template match="FILES">
> <xsl:apply-templates select="*[generate-id(.) =
>     generate-id(key('rows', concat(name(), '+', name))[1])]"/>
> </xsl:template>
>
> <xsl:template match="FILES/*">
>                    <xsl:value-of select="name"/>
>                    <xsl:for-each select="key('rows', name)"> 
>                    <xsl:value-of select="$newline"/>
>                    <xsl:value-of select="project_name"/>
>                    <xsl:value-of select="$newline"/>
>                 </xsl:for-each>
> </xsl:template>

In this template you're printing the name of the selected record (i.e.
'Fred', 'Fred' and 'Harry'. Then you're trying to recover all those
records whose key value is the same as that name (e.g. those records
whose key value is simply 'Fred'). As you've seen above, the key
values are actually combinations of the name of the record element and
the name element child of the record, so you end up iterating over an
empty node set, which is why you don't get the project_names coming
out. What you wanted to do was:

  <xsl:for-each select="key('rows', concat(name(), '+', name))">
    <xsl:value-of select="$newline" />
    <xsl:value-of select="project_name" />
    <xsl:value-of select="$newline" />
  </xsl:for-each>

> I get FredFredHarry. So its removed the extra Fred but doesnt print the
> project_names. If I change this so that instead of name I group by
> project-name..thus

This had exactly the same problem as above, but was otherwise
perfectly correct as far as I could tell :)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]