|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








