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

Re: having difficulty with XSL/XML statement

Subject: Re: having difficulty with XSL/XML statement
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Mar 2004 23:21:09 -0500
xml statement
At 2004-03-29 22:08 -0500, Alan Stein wrote:
I have small XSL example which is posing rather large difficulty for me... (I think due to the use of parenthesis needed for document order location path).

Not sure why you think parentheses are needed ... the following-sibling axis is already in document order.


In the following XML document, I need to be able to query the following:

1) The number of reports which contain an "a" or "b" code where the last code (in document order) which is either an "a" or "b" is an "a".

Which is to say there is an "a" without a "b" following sibling.


*correct number is 3 *

2) The number of reports which contain an "a" or "b" code where the last code (in document order) which is either an "a" or "b" is a "b".

Which is to say there is a "b" without an "a" following sibling.


*correct number is 1*

I hope the example below helps.


............... Ken

t:\ftemp>type stein.xml
<?xml version="1.0" encoding="UTF-8"?>
<reportlist>
  <report>
      <code type="a"/>
      <code type="b"/>
      <code type="c"/>
  </report>
  <report>
      <code type="a"/>
      <code type="b"/>
      <code type="a"/>
  </report>
  <report>
      <code type="z"/>
      <code type="a"/>
      <code type="d"/>
  </report>
  <report>
      <code type="a"/>
      <code type="e"/>
      <code type="f"/>
  </report>
  <report>
      <code type="e"/>
  </report>
</reportlist>

t:\ftemp>type stein.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
  1) The number of reports which contain an "a" or "b" code where
  the last code (in document order) which is either an "a" or
  "b" is an "a": <xsl:value-of select="
  count(/*/report[code[@type='a'][not(following-sibling::code/@type='b')]])"/>
  2)  The number of reports which contain an "a" or "b" code where
  the last code (in document order) which is either an "a" or
  "b" is a "b":  <xsl:value-of select="
  count(/*/report[code[@type='b'][not(following-sibling::code/@type='a')]])"/>

</xsl:template>

</xsl:stylesheet>
t:\ftemp>saxon stein.xml stein.xsl

  1) The number of reports which contain an "a" or "b" code where
  the last code (in document order) which is either an "a" or
  "b" is an "a": 3
  2)  The number of reports which contain an "a" or "b" code where
  the last code (in document order) which is either an "a" or
  "b" is a "b":  1
t:\ftemp>


-- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc

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.