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

Re: XPath Predicate Nuance

Subject: Re: XPath Predicate Nuance
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 06 Oct 2004 20:28:28 -0400
xsl predicate
At 2004-10-06 15:13 -0700, David P. Nesbitt wrote:
I am getting some unexpect results from an XPath
predicate.

Yours is a common mistake made by my students who have looked at XPath before taking a class.


I am trying to load the unique values of
an element into a variable.  The XML file is grouped
by this element.  I want to treat the absence of the
element as a value as well (the "null" value if you
will).  However, I can't get the XPath predicate to
filter out multiple "null" values.

You are forgetting that "preceding-sibling::" looks at *all* preceding siblings, not just the closest preceding sibling.


I am including below a data file, stylesheet, expected
output and observed output.

Thank you, that made it easy to modify to illustrate the fix.


If you can see anything
wrong, I would most appreciate your assistance.

Use a predicate "[1]" to talk about the immediately preceding sibling, not *all* preceding siblings.


I hope this helps.

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

p.s. your use of boolean() on a node set is redundant ... the processor is already converting both operands to boolean when the operator is boolean.

T:\ftemp>type nesbitt.xml
<a>
 <b>
  <c>123</c>
  <d>000</d>
 </b>
 <b>
  <c>123</c>
  <d>000</d>
 </b>
 <b>
  <d>000</d>
 </b>
 <b>
  <d>000</d>
 </b>
 <b>
  <c>456</c>
  <d>000</d>
 </b>
 <b>
  <c>456</c>
  <d>000</d>
 </b>
 <b>
  <c>789</c>
  <d>000</d>
 </b>
</a>

T:\ftemp>type nesbitt.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="text"/>
 <xsl:template match="a">
   <xsl:variable name="unique-cs"
select="/a/b[(not(preceding-sibling::b) or
             (not(c) and preceding-sibling::b[1]/c) or
             (c and not(c=preceding-sibling::b[1]/c)))]"/>
   <xsl:for-each select="$unique-cs">
    <xsl:value-of select="c"/>
    <xsl:text>
 </xsl:text>
   </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

T:\ftemp>saxon nesbitt.xml nesbitt.xsl
123

 456
 789

T:\ftemp>

--
Upcoming publicly-subscribed XSL delivery: Helsinki Oct 18-20,2004
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
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.