This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In some reading I have seen expressions like this: Say, for example select all titles with "The Good, The Bad and The Ugly... title[.="The Good, The Bad and The Ugly"] title["The Good, The Bad and The Ugly"] Is this just a matter of style or is there more that I am missing ? In the limited exposure that I have, these two expressions seem to do the same thing. For some reason, I prefer the second option... Thanks for any input. - madhav
Hi Madhav, . (dot) refers to the context node. In your example, both expression mean the same. There is not standard way of writing this expression, though most people actually use the second form (without the ".=" ). Cheers
These two predicates mean two different things. [.="The Good, The Bad and The Ugly"] means that the title element will be chosen when the title element contains this string as its data. The predicate ["The Good, The Bad and The Ugly"] will _always_ evaluate to true since this string "The Good, The Bad and The Ugly" is not empty. An empty string will make the predicate return false. Cheers, Dan
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Joined: Nov 22, 2008
Dan, You do not seem to have used XPath extensively, even if you seem to have some time reading the spec If you look at the spec carefully, indeed, there is no mention of this abbreviated form. However most parsers will understand it. In XPath, leaving out the ".=" in a predicate is quite common as it simplifies writing long expressions. Cheers
Joined: Jul 09, 2001
Please be kind enough to check it with the following code -
XML Spy 4.4 and xalan output the following -
Joined: Nov 22, 2008
Dan, Damn ! You were right Thanks for your clear demonstration, and appologises for my sarcasm After seing your reply, I went straight to my favourite XSLT transformer to prove you wrong, and well, I have to admit that I'm lacking some practise in that area Madhav, Sorry for the confusion. I've been confusing this with the abbreviated form element (== element[position()=1]). Cheers
Joined: Jun 03, 2000
Thanks, Dan. Appreciate your example. Although I made a few changes to understand your point. I was interested in selecting an element based on its content. Say I want to select all elements of a specific type. To understand this I used your code and this is what I have:
Apparently, as you said, the rule A is selected for all elements. Rule B is selected only for that element whose content matches 'desk'. (For the desk, rule A is not selected since it has its own rule). WOW! So its not a convention, its a valid selection rule and that's what I wanted to understand. Thanks. - madhav............used XML Spy. [ January 17, 2003: Message edited by: Madhav Lakkapragada ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: xpath exp - conventions or just a matter of style ?