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

Re: problem with keys and Meunchian method

Subject: Re: problem with keys and Meunchian method
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Wed, 17 Nov 2004 22:03:13 +0100
xsl match duplicate keys
Hi,

How about a key that is defined as follows:

<xsl:key name="books-in-last-prodline-by-name" match="prodline[code='PL1'][last()]/product/book" use="name" />

Then you do a for-each on all books in the last prodline and test for each whether it is the last occurrence in document order:

<xsl:for-each select="//prodline[code='PL1'][last()]/product/book">
  <xsl:if test="generate-id(.) = generate-id(key('books-in-last-prodline-by-name', name)[last()])">
    <!-- found the last one! -->
  <xsl:if>
</xsl:for-each>

Does this help?

Grtz,
Geert

mark_fletcher@xxxxxxxxxxxxxx wrote:

Hi all,

I'm having a problem pulling distinct nodes out of some xml with duplicate
values at multiple levels.  In all cases, I want to get the data from the
last node of a set that shares duplicate values.  (This xml will be in a
file that gets appended to multiple times.  So I can assume that the last
tags are the most current.)

In the xml below, what I'm trying to do is get a list of distinct book/code
values from the last prodline where name=PL1.  I can successfully get the
prodline using this select statement:

<xsl:for-each select="prodline[code='PL1'][last()]">

But I'm having no luck getting a list of distinct book/code values from
this particular prodline.  I've tried creating keys and using the Meunchian
method of comparing generate-id() values, but to no avail. Any help would
be greatly appreciated!


Here's the xml:


<prodlines>
  <prodline>
    <name>Product Line 1</name>
    <code>PL1</code>
    <product>
      <name>Product 1</name>
      <code>P1</code>
      <book>
        <name>Book 1</name>
        <code>B1</code>
      </book>
      <book>
        <name>Book 2</name>
        <code>B2</code>
      </book>
    </product>
    <product>
      <name>Product 2</name>
      <code>P2</code>
      <book>
        <name>Book 1</name>
        <code>B1</code>
      </book>
      <book>
        <name>Book 3</name>
        <code>B3</code>
      </book>
      <book>
        <name>Book 4</name>
        <code>B4</code>
      </book>
    </product>
  </prodline>
  <prodline>
    <name>Product Line 2</name>
    <code>PL2</code>
    <product>
      <name>Product 1</name>
      <code>P1</code>
      <book>
        <name>Book 1</name>
        <code>B1</code>
      </book>
    </product>
  </prodline>
  <prodline>
    <name>Product Line 1 (ver 2)</name>
    <code>PL1</code>
    <product>
      <name>Product 1</name>
      <code>P1</code>
      <book>
        <name>Book 1</name>
        <code>B1</code>
      </book>
      <book>
        <name>Book 2</name>
        <code>B2</code>
      </book>
      <book>
        <name>Book 5</name>
        <code>B5</code>
      </book>
    </product>
    <product>
      <name>Product 2</name>
      <code>P2</code>
      <book>
        <name>Book 1</name>
        <code>B1</code>
      </book>
      <book>
        <name>Book 2</name>
        <code>B2</code>
      </book>
      <book>
        <name>Book 3</name>
        <code>B3</code>
      </book>
      <book>
        <name>Book 4</name>
        <code>B4</code>
      </book>
    </product>
  </prodline>
</prodlines>


Mark Fletcher PeopleSoft Language Engineering 925.694.3753 mark_fletcher@xxxxxxxxxxxxxx




-- Geert.Josten@xxxxxxxxxxx IT-consultant at Daidalos BV, Zoetermeer (NL)

http://www.daidalos.nl/
tel:+31-(0)79-3316961
fax:+31-(0)79-3316464

GPG: 1024D/12DEBB50

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.