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: unique elements from different sourcefile


Hi Thomas,

> just curious,
>
> what do i have to do when i want to use the muench method or at
> least xsl:keys on a different document. i thought i would need two
> for-eachs and the xsl:key just has to be defined in the "scope" of
> the different document.
>
> is it that way that with the first for-each on the different
> document i get into the right scope and with the second i create my
> index with xsl:key. could this problem be solved via muench method.
> i am just asking because obviously i don't understand it completely.

To use the Muenchian Method with scoping, you have to create keys that
index each node by a combination of the value you want to group by and
an identifier from the scoping element.

In your case, you need to create a key that indexes each element-name
element by both its name attribute and the name attribute of the
ancestor element element:

<xsl:key name="elements" match="element-name"
         use="concat(ancestor::element/@name, '+', @name)" />

This means, for example, that you can get a list of all the 'meta'
element-name elements within the 'head' element with:

  key('elements', 'head+meta')

This ensures that there's a different 'partition' within the key table
for each of the 'element' elements in your document. All the keys for
element-name elements from that particular element start with the same
string (all key values for the element-names within the 'head' element
start with 'head+').
  
So to list all the unique element-names within a particular element
you'd have something like:

<xsl:template match="element">
  <xsl:variable name="element" select="@name" />
  <xsl:for-each
    select=".//element-name
              [generate-id() =
               generate-id(key('elements',
                               concat($element, '+', @name))[1])]">
    <xsl:value-of select="@name" />
    <xsl:if test="position() != last()">, </xsl:if>
  </xsl:for-each>
</xsl:template>

I hope that helps,

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]