<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>getting an attrib value from another attrib value</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">This may be more XPath than XQuery so I hope you don't mind me posting here.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I want to write a query that given a string (let's say &quot;Torbay&quot;) will return the uid attribute of the element with the name attribute equal to the string value.</FONT></P>

<P><FONT SIZE=2 FACE="Arial">I have only got so far as being able to get the whole node (i.e. including children) with the matching name attribute as follows:</FONT></P>

<P><FONT SIZE=2 FACE="Arial">for $areaserved in doc(&quot;...&quot;)/*[@name = &quot;Torquay&quot;] return $areaserved</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I should say that the matching name attribute could appear at any level in the XML document and may or may not have child elements.</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Example XML:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&lt;county name=&quot;Devon&quot; uid=&quot;0&quot;&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; &lt;district uid=&quot;8&quot; name=&quot;Torbay&quot;&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;town uid=&quot;210&quot; name=&quot;Brixham&quot; pct=&quot;Torbay&quot;/&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;town uid=&quot;211&quot; name=&quot;Paignton&quot; pct=&quot;Torbay&quot;/&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;town uid=&quot;212&quot; name=&quot;Torquay&quot; pct=&quot;Torbay&quot;&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;settlement name=&quot;Babbacombe&quot; uid=&quot;979&quot;/&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;settlement name=&quot;Barton&quot; uid=&quot;803&quot;/&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;settlement name=&quot;Chelston&quot; uid=&quot;804&quot;/&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/town&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; &lt;/district&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&lt;/county&gt;</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Many Thanks</FONT>

<BR><FONT SIZE=2 FACE="Arial">Rob Walpole</FONT>
</P>

</BODY>
</HTML>