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

RE: Need help OR'ing in XPATH.

Subject: RE: Need help OR'ing in XPATH.
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Thu, 23 Mar 2006 04:26:27 +0000
need ing
No, this is absolutely *not* recommended. If you use /text(), your code will
be sensitive to the presence of comments within the text, and it's very
unusual that you should want comments to make any difference.

Fair enough!!
But Mike, I was concerned about a scenario where there might be other child nodes as stated in my example.. and I was not actually talking about the case where there are comments in the text nodes.
like
<chapter>
<owner>aaa
<id>222</id>
</owner>
</chapter>


selecting owner in the above example would give you aaa and 222..

so to select just aaa, you WILL have to say owner/text()..Now Let me put the question back to you.

What would you do if the xml was..

<chapter>
       <owner>aaa <!-- second-->bbb
       <id>222</id>
    </owner>
    </chapter>

and you dont want the value of id to be in the output???

clearly your selecting owner would fail as it will be aaabbb and 222 and not just the text value of owner..

I agree that even owner/text() would fail in this case, as it will be just aaa and not aaabbb as we would think as aaa would be owner/text()[1] and bbb would be owner/text()[2]

This is very similar to the case like ..

<owner>
aaa
<id>111</id>
bbb
</owner>

Your introduction of a comment node in the text and my introduction of an <id> node to me is not much different only that the comment nodes are ignored. and id node wont be.

So The point you picked Mike , is definitely something to be careful about when you see it. because people will no doubt miss the point that the comment node is actually a node.Nevertheless, it is important for them to know what to do when they have a situation like..
<owner>
aa<!---next text -->a
<id>222</id>
</owner>


when both your suggestion and my suggestion will fail.
mine
<xsl:a-t select="book[owner/text()='aaa' or
chapter/owner/text()='aaa']"/>

will fail because

owner/text() is aa

and yours

<xsl:a-t select="book[owner='aaa' or
chapter/owner='aaa']"/>

will fail because

owner is aaa222

so
<owner>aa<!--three stars-->a</owner>

then owner='aaa' will succeed, but owner/text() will fail.

is not entirely true in all cases.


and so ..

No, this is absolutely *not* recommended

is also not true in all the cases, especially the case i started off discussiong about, where there could be a child node. that is why i said.."you may not have this problem".


The question again passes on to you to suggest on the best way for a case like
<owner>
aa<!---next text -->a
<id>222</id>
</owner>


Vasu


From: "Michael Kay" <mike@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  Need help OR'ing in XPATH.
Date: Wed, 22 Mar 2006 12:49:57 -0000

> not that it will happen to you but its a best practice to
> refer a text value
> of a node by text().
>
> <xsl:a-t select="book[owner/text()='aaa' or
> chapter/owner/text()='aaa']"/>
>

No, this is absolutely *not* recommended. If you use /text(), your code will
be sensitive to the presence of comments within the text, and it's very
unusual that you should want comments to make any difference.


owner='aaa' compares the string value of the owner element against the
string 'aaa'. If the owner element is

<owner>aa<!--three stars-->a</owner>

then owner='aaa' will succeed, but owner/text() will fail.

Michael Kay
http://www.saxonica.com


_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger 7.5 today! http://join.msn.com/messenger/overview


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.