<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: XPath brain teasers: graph queries in XPath 1.0</title>
	<atom:link href="http://stage.vambenepe.com/archives/181/feed" rel="self" type="application/rss+xml" />
	<link>http://stage.vambenepe.com/archives/181</link>
	<description>IT management in a changing IT world</description>
	<pubDate>Tue, 06 Jan 2009 04:28:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: William Vambenepe</title>
		<link>http://stage.vambenepe.com/archives/181#comment-40850</link>
		<dc:creator>William Vambenepe</dc:creator>
		<pubDate>Mon, 05 May 2008 18:50:09 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-40850</guid>
		<description>Hi Kas. Sure XQuery can do the job, as can many other query languages. Which is why I start by showing how to do it with SPARQL and CMDBf query.

The point here was not to find the "right" way to do it, but to find how far XPath can be abused in an attempt to use it.

That's why I wrote somewhere in the post that "using the right tool for the job is just no fun" and that "practically-minded people would have long moved to another query language or at least to version 2.0 of XPath".

William</description>
		<content:encoded><![CDATA[<p>Hi Kas. Sure XQuery can do the job, as can many other query languages. Which is why I start by showing how to do it with SPARQL and CMDBf query.</p>
<p>The point here was not to find the &#8220;right&#8221; way to do it, but to find how far XPath can be abused in an attempt to use it.</p>
<p>That&#8217;s why I wrote somewhere in the post that &#8220;using the right tool for the job is just no fun&#8221; and that &#8220;practically-minded people would have long moved to another query language or at least to version 2.0 of XPath&#8221;.</p>
<p>William</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kas Thomas</title>
		<link>http://stage.vambenepe.com/archives/181#comment-40273</link>
		<dc:creator>Kas Thomas</dc:creator>
		<pubDate>Thu, 01 May 2008 12:57:34 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-40273</guid>
		<description>Isn't the answer to use XQuery?</description>
		<content:encoded><![CDATA[<p>Isn&#8217;t the answer to use XQuery?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul King</title>
		<link>http://stage.vambenepe.com/archives/181#comment-38133</link>
		<dc:creator>Paul King</dc:creator>
		<pubDate>Fri, 04 Apr 2008 00:13:59 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-38133</guid>
		<description>I updated the Groovy example to use David's version.</description>
		<content:encoded><![CDATA[<p>I updated the Groovy example to use David&#8217;s version.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Vambenepe</title>
		<link>http://stage.vambenepe.com/archives/181#comment-38042</link>
		<dc:creator>William Vambenepe</dc:creator>
		<pubDate>Wed, 02 Apr 2008 17:17:57 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-38042</guid>
		<description>You are right David, the [][] form is much better than the [[]] form. Thank you for pointing this out. Note to self: equality is a transitive relation. Duh.

Thanks for the Groovy code Paul (Paul has more XPath/Groovy examples &lt;a href="http://groovy.codehaus.org/Reading+XML+with+Groovy+and+XPath" rel="nofollow"&gt;here&lt;/a&gt; for those interested).

BTW, if anyone wants to play with this graph query but doesn't have an XPath tool handy, you can use &lt;a href="http://coderstoolbox.net/xml/xpath.php" rel="nofollow"&gt;this one&lt;/a&gt;. Then use &lt;a href="http://stage.vambenepe.com/pages/xpath-brain-teaser.xml" rel="nofollow"&gt;http://stage.vambenepe.com/pages/xpath-brain-teaser.xml&lt;/a&gt; as the URL to the XML file to load the document that I use in this example.</description>
		<content:encoded><![CDATA[<p>You are right David, the [][] form is much better than the [[]] form. Thank you for pointing this out. Note to self: equality is a transitive relation. Duh.</p>
<p>Thanks for the Groovy code Paul (Paul has more XPath/Groovy examples <a href="http://groovy.codehaus.org/Reading+XML+with+Groovy+and+XPath" rel="nofollow">here</a> for those interested).</p>
<p>BTW, if anyone wants to play with this graph query but doesn&#8217;t have an XPath tool handy, you can use <a href="http://coderstoolbox.net/xml/xpath.php" rel="nofollow">this one</a>. Then use <a href="http://stage.vambenepe.com/pages/xpath-brain-teaser.xml" rel="nofollow">http://stage.vambenepe.com/pages/xpath-brain-teaser.xml</a> as the URL to the XML file to load the document that I use in this example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David  Carlisle</title>
		<link>http://stage.vambenepe.com/archives/181#comment-38025</link>
		<dc:creator>David  Carlisle</dc:creator>
		<pubDate>Wed, 02 Apr 2008 13:30:24 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-38025</guid>
		<description>sorry 2nd version got eaten by the comment system

&#60;xsl:variable name="a" select="/doc/person[@name='alan']/g[not(.=preceding-sibling::g)]"/&#62;
&#60;xsl:variable name="p" select="/doc/person[@name='paul']/g"/&#62;
&#60;xsl:variable name="i" select="/doc/person[@name='ivan']/g"/&#62;

&#60;xsl:copy-of select="$a[.=$p][.=$i]"/&#62;</description>
		<content:encoded><![CDATA[<p>sorry 2nd version got eaten by the comment system</p>
<p>&lt;xsl:variable name=&#8221;a&#8221; select=&#8221;/doc/person[@name='alan']/g[not(.=preceding-sibling::g)]&#8220;/&gt;<br />
&lt;xsl:variable name=&#8221;p&#8221; select=&#8221;/doc/person[@name='paul']/g&#8221;/&gt;<br />
&lt;xsl:variable name=&#8221;i&#8221; select=&#8221;/doc/person[@name='ivan']/g&#8221;/&gt;</p>
<p>&lt;xsl:copy-of select=&#8221;$a[.=$p][.=$i]&#8220;/&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David  Carlisle</title>
		<link>http://stage.vambenepe.com/archives/181#comment-38024</link>
		<dc:creator>David  Carlisle</dc:creator>
		<pubDate>Wed, 02 Apr 2008 13:27:47 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-38024</guid>
		<description>I'd write the fist expression as

/doc/person[@name='alan']/g
          [.=../../person[@name='paul']/g]
          [.=../../person[@name='ivan']/g]"

which using a [][] form rather than [  []] doesn't have quite such bad behaviour even if evaluated naively.

And adding as you suggested [not(.=preceding-sibling::g)] if you need to filter out duplicates)

Of course if your xpath is being hosted by xslt or any other API that allows you to use variables it's easy to avoid the potentially expensive ../../person steps








but it's quite likley that an xpath engine will rewrite the first form to the second anyway, inferring local variables to take the constant expression out of the loop.

David</description>
		<content:encoded><![CDATA[<p>I&#8217;d write the fist expression as</p>
<p>/doc/person[@name='alan']/g<br />
          [.=../../person[@name='paul']/g]<br />
          [.=../../person[@name='ivan']/g]&#8221;</p>
<p>which using a [][] form rather than [  []] doesn&#8217;t have quite such bad behaviour even if evaluated naively.</p>
<p>And adding as you suggested [not(.=preceding-sibling::g)] if you need to filter out duplicates)</p>
<p>Of course if your xpath is being hosted by xslt or any other API that allows you to use variables it&#8217;s easy to avoid the potentially expensive ../../person steps</p>
<p>but it&#8217;s quite likley that an xpath engine will rewrite the first form to the second anyway, inferring local variables to take the constant expression out of the loop.</p>
<p>David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul King</title>
		<link>http://stage.vambenepe.com/archives/181#comment-38005</link>
		<dc:creator>Paul King</dc:creator>
		<pubDate>Wed, 02 Apr 2008 07:58:40 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-38005</guid>
		<description>You could solve it using Groovy as follows:

def root = new XmlParser().parseText(xml)
Set groups = root.person.g.collect{ it.text() }
assert groups.findAll{ groupId -&#62;
  root.person.g.findAll{
    it.text() == groupId
  }.'..'.'@name'.containsAll(['alan', 'paul', 'ivan'])
} == ['2', '4']</description>
		<content:encoded><![CDATA[<p>You could solve it using Groovy as follows:</p>
<p>def root = new XmlParser().parseText(xml)<br />
Set groups = root.person.g.collect{ it.text() }<br />
assert groups.findAll{ groupId -&gt;<br />
  root.person.g.findAll{<br />
    it.text() == groupId<br />
  }.&#8217;..&#8217;.'@name&#8217;.containsAll(['alan', 'paul', 'ivan'])<br />
} == ['2', '4']</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Willis</title>
		<link>http://stage.vambenepe.com/archives/181#comment-37544</link>
		<dc:creator>John Willis</dc:creator>
		<pubDate>Thu, 27 Mar 2008 17:08:23 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-37544</guid>
		<description>And we were getting along so well and you had to go ahead and pull a stunt like this... :) 

john</description>
		<content:encoded><![CDATA[<p>And we were getting along so well and you had to go ahead and pull a stunt like this&#8230; :) </p>
<p>john</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Vambenepe&#8217;s blog &#187; Blog Archive &#187; How not to re-use XML technologies</title>
		<link>http://stage.vambenepe.com/archives/181#comment-37541</link>
		<dc:creator>William Vambenepe&#8217;s blog &#187; Blog Archive &#187; How not to re-use XML technologies</dc:creator>
		<pubDate>Thu, 27 Mar 2008 16:24:25 +0000</pubDate>
		<guid isPermaLink="false">http://stage.vambenepe.com/archives/181#comment-37541</guid>
		<description>[...] case) in a scenario in which it is not the right tool for the job (graph queries), check out this XPath brain teasers [...]</description>
		<content:encoded><![CDATA[<p>[...] case) in a scenario in which it is not the right tool for the job (graph queries), check out this XPath brain teasers [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
