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

RE: 2 Predicates in 1 for-each, possible?

Subject: RE: 2 Predicates in 1 for-each, possible?
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Tue, 10 Feb 2004 14:52:29 -0800
communication predicates
A predicate is used to filter a selection by converting the contents to a boolean value. 

Your selection is //communication/email, which translates to /descendant-or-self::node()/communication/email.
Alone this will return all email elements with a communication element as parent. 

Adding the predicate [emailaddress] specifies that you only want email nodes with an emailaddress node as a child. emailaddress will evaluate to true if there is an emailaddress child element of the selected node.

the predicate [//communication2[emailaddress2]] evaluates to true when there exists a communication2 element with a child emailaddress2 element anywhere in the document.

the predicate [emailaddress or //communication2[emailaddress2]] returns true when either of the two conditions described above are true.

It looks like you really want the union of all communication/email and communication2/emailaddress2 nodes.

<xsl:for-each select="//communication/email[emailaddress] | //communication2/emailaddress2">

Good luck,
Josh

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Bert
Sent: Tuesday, February 10, 2004 12:29 PM
To: Xsl-List
Subject:  2 Predicates in 1 for-each, possible?


Hello,

Allow me to ask a question about 2 predicates in 1 for-each.

I have this xml-file:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="persons01.xsl"?>

<root>
 <organisation>
  <communication>
   <email>
    <emailaddress>e-mail@xxxxxxx(1)</emailaddress>
   </email>
  </communication>
  <communication2>
   <emailaddress2>e-mail@xxxxxxx(2)</emailaddress2>
  </communication2>
 </organisation>
 <organisation>
  <communication>
   <email>
    <emailaddress>e-mail@xxxxxx(1)</emailaddress>
   </email>
  </communication>
  <communication2>
   <emailaddress2>e-mail@xxxxxx(2)</emailaddress2>
  </communication2>
 </organisation>
</root>

I use this stylesheet to collect some information:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" indent="yes"/>
 <xsl:template match="/">
  <document>
   <xsl:for-each select="//communication/email[emailaddress or
//communication2[emailaddress2]]">
    <xsl:sort select="."/>
    <xsl:value-of select="."/>
    <xsl:if test="position() != last()">,
    </xsl:if>
   </xsl:for-each>
  </document>
 </xsl:template>
</xsl:stylesheet>

I expected to get the following result:
e-mail@xxxxxxx(1), e-mail@xxxxxxx(2), e-mail@xxxxxx(1), e-mail@xxxxxx(2)

But what I get is this:
e-mail@xxxxxxx(1) , e-mail@xxxxxx(1)

It is obvious there is something wrong in my for-each-statement, but what?

Any help is this is welcome.

Kind regards,
Bert



 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.