user851380
user851380

Reputation: 339

using xquery to extract attribute value from xml which contains namespaces

I am trying to extract the attribute value of element in the following xml file

<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0" xmlns:xlink="http://www.w3.org/1999/xlink" name="TimeSeriesServer THREDDS Catalog">
    <service base="http://tsds.net/tsds/" serviceType="OpenDAP"/>
    <catalogRef xlink:title="local" xlink:href="test/ncml_catalog.thredds"/>
    <catalogRef xlink:title="remote" xlink:href="http://virbo.org/metamag/viewDataFile.jsp?docname=C6D5623A-ADEC-8397-88A7-DD62A37BA490&amp;filetype=data"/>
</catalog>

and the xquery is

declare namespace prefix= "http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0";
declare namespace xlink="http://www.w3.org/1999/xlink";

let $xslt:= "/db/virbo/xq/merge/merge.xsl"
let $xml := "/db/virbo/xq/merge/F8ADA960-F16B-5F72-6B09-BE1FE64E5BB1.xml"

return 
   <li>{doc($xml)/prefix:catalog/prefix:catalogRef/@tile}</li>

it suppose to give me test/ncml_catalog.thredds and http://virbo.org/metamag/viewDataFile.jsp?docname=C6D5623A-ADEC-8397-88A7-DD62A37BA490&amp;filetype=data but the last line seems not working and don't know why. Thanks inadvance

Upvotes: 2

Views: 2744

Answers (1)

Oliver Hallam
Oliver Hallam

Reputation: 4262

Your @title is matching a title attribute in no namespace, yet you are looking for a title element in the xlink namespace. Changing the test to @xlink:title will fix this.

The path is returning an attribute node which is then copied into the li element, which will give a result something like:

<li xlink:title="..." />

Whereas I suspect you actually want the data from the attribute.

Change your last line to

<li>{doc($xml)/prefix:catalog/prefix:catalogRef/@xlink:tile/data(.)}</li>

and everything should work.

Upvotes: 2

Related Questions