xsl-list
[Top] [All Lists]

Re: XPath Predicate Nuance

2004-10-06 18:08:22
Ken,

Thanks a bunch for the help.  I really appreciate it.

Regards,
Dave

--- "G. Ken Holman" <gkholman(_at_)CraneSoftwrights(_dot_)com>
wrote:

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(_at_)CraneSoftwrights(_dot_)com
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



--+------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





                
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


<Prev in Thread] Current Thread [Next in Thread>