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

Re: unique elements from different sourcefile

Subject: Re: unique elements from different sourcefile
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 3 Jan 2002 18:44:19 +0000
unusual element names
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


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.