<?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>
	<lastBuildDate>Wed, 17 Mar 2010 19:31:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</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 &quot;right&quot; way to do it, but to find how far XPath can be abused in an attempt to use it.

That&#039;s why I wrote somewhere in the post that &quot;using the right tool for the job is just no fun&quot; and that &quot;practically-minded people would have long moved to another query language or at least to version 2.0 of XPath&quot;.

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&#039;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&#039;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=&quot;http://groovy.codehaus.org/Reading+XML+with+Groovy+and+XPath&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; for those interested).

BTW, if anyone wants to play with this graph query but doesn&#039;t have an XPath tool handy, you can use &lt;a href=&quot;http://coderstoolbox.net/xml/xpath.php&quot; rel=&quot;nofollow&quot;&gt;this one&lt;/a&gt;. Then use &lt;a href=&quot;http://stage.vambenepe.com/pages/xpath-brain-teaser.xml&quot; rel=&quot;nofollow&quot;&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

&lt;xsl:variable name=&quot;a&quot; select=&quot;/doc/person[@name=&#039;alan&#039;]/g[not(.=preceding-sibling::g)]&quot;/&gt;
&lt;xsl:variable name=&quot;p&quot; select=&quot;/doc/person[@name=&#039;paul&#039;]/g&quot;/&gt;
&lt;xsl:variable name=&quot;i&quot; select=&quot;/doc/person[@name=&#039;ivan&#039;]/g&quot;/&gt;

&lt;xsl:copy-of select=&quot;$a[.=$p][.=$i]&quot;/&gt;</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&#039;d write the fist expression as

/doc/person[@name=&#039;alan&#039;]/g
          [.=../../person[@name=&#039;paul&#039;]/g]
          [.=../../person[@name=&#039;ivan&#039;]/g]&quot;

which using a [][] form rather than [  []] doesn&#039;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&#039;s easy to avoid the potentially expensive ../../person steps








but it&#039;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 -&gt;
  root.person.g.findAll{
    it.text() == groupId
  }.&#039;..&#039;.&#039;@name&#039;.containsAll([&#039;alan&#039;, &#039;paul&#039;, &#039;ivan&#039;])
} == [&#039;2&#039;, &#039;4&#039;]</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>
