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

RE: matching the first following sibling

Subject: RE: matching the first following sibling
From: kakridge@xxxxxxxxxxxxx
Date: Thu, 22 Jan 2004 11:33:51 -0500
xsl first following sibling
Your example didn't provide $productId.  You were on the right track,
but using this method is much cleaner.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="total" match="Substance" use="productId"/>

	<xsl:template match="ProductList">
		<xsl:for-each select="Substance[productId[not(. =
preceding::productId)]]">
			<xsl:sort select="Substance/productId"/>
			<xsl:value-of select="concat(productId, ': ')"/>
			<xsl:value-of select="concat(sum(key('total',
productId)/num), ' ')"/><br/>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Biying Huang
Sent: Thursday, January 22, 2004 10:56 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Cc: btusdin@xxxxxxxxxxxxxxxx
Subject:  matching the first following sibling

Dear All,

I have trouble with matching the first following sibling which has a
child's value differ from the current one's.

I need my output look like this:

3000: 9
5000: 5
4000: 8

But I can only get the first line,  3000 : 9

Here is my xslt:

<xsl:template match="ProductList">
    <xsl:apply-templates select="Substance[position() = 1 ]" />
</xsl:template>

<xsl:template match="Substance">
  <xsl:value-of select = "productId"/>
   :
  <xsl:value-of select = "sum( num  |
following-sibling::Substance[productId = $productId ]/num)" />

  <!--  now check if there is another unique product, if so, call this
template recursively, but this DOES NOT work   -->
  <xsl:apply-templates select="following-sibling::Substance[productId
!=  ./productId and position() = 1 ]" />

</xsl:template>


I have this xml data:

<ProductList>
  <Substance>
      <productId>3000</productId>
      <num>3</num>
   </Substance>
  <Substance>
      <productId>4000</productId>
      <num>4</num>
   </Substance>
  <Substance>
      <productId>3000</productId>
      <num>3</num>
   </Substance>
  <Substance>
      <productId>5000</productId>
      <num>5</num>
   </Substance>
  <Substance>
      <productId>4000</productId>
      <num>4</num>
   </Substance>
  <Substance>
      <productId>3000</productId>
      <num>3</num>
   </Substance>
 </ProductList>



Thanks in advance for your help.

Biying Huang


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 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.