<!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 "Torbay") 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("...")/*[@name = "Torquay"] 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"><?xml version="1.0" encoding="UTF-8"?></FONT>
<BR><FONT SIZE=2 FACE="Arial"><county name="Devon" uid="0"></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <district uid="8" name="Torbay"></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <town uid="210" name="Brixham" pct="Torbay"/></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <town uid="211" name="Paignton" pct="Torbay"/></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <town uid="212" name="Torquay" pct="Torbay"></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <settlement name="Babbacombe" uid="979"/></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <settlement name="Barton" uid="803"/></FONT>
<BR><FONT SIZE=2 FACE="Arial"> <settlement name="Chelston" uid="804"/></FONT>
<BR><FONT SIZE=2 FACE="Arial"> </town></FONT>
<BR><FONT SIZE=2 FACE="Arial"> </district></FONT>
<BR><FONT SIZE=2 FACE="Arial"></county></FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Many Thanks</FONT>
<BR><FONT SIZE=2 FACE="Arial">Rob Walpole</FONT>
</P>
</BODY>
</HTML>