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

Re: opposite of preceding-sibling

Subject: Re: opposite of preceding-sibling
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 10 Aug 2001 16:23:18 +0100
opposite of preceding
Hi Jan,

To answer your subject-line's question, the opposite of
preceding-sibling is following-sibling.

It's hard to tell because I can't see how the source XML you gave tied
up with the result that you were after, but I think that this is a
grouping problem. You want to group the index elements by the artnr
element they're associated with in a particular row.

So index the row elements by artnr:

<xsl:key name="row-by-artnr" match="row" use="artnr" />

That means that if you do:

  key('row-by-artnr', 'gh')

you'll get all the row elements whose child artnr element has the
value 'gh'.

Then it looks as though you want to create a col element for each
unique artnr, with an artnr element inside with a nummer attribute
holding the value of the artnr from the original XML. You can do this
with:

  <xsl:for-each select="/test/result/row
                          [count(.|key('row-by-artnr', artnr)[1]) =
                           1]">
    <col>
      <artnr nummer="{artnr}">
        ...
      </artnr>
    </col>
  </xsl:for-each>

Within the artnr element, you want to add copies of all the index
elements from the row elements with that value for the artnr element.
You can retrieve those with the key:

  <xsl:for-each select="/test/result/row
                          [count(.|key('row-by-artnr', artnr)[1]) =
                           1]">
    <col>
      <artnr nummer="{artnr}">
        <xsl:copy-of select="key('row-by-artnr', artnr)/index" />
      </artnr>
    </col>
  </xsl:for-each>

Of course you could use templates rather than xsl:for-each if you
prefer.

You can find more on the theory at
http://www.jenitennison.com/xslt/grouping/muenchian.html.

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.