2

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

1
  • 1
    is @tile a typo for @title or @href? Commented Aug 5, 2011 at 17:23

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

alternately, use string() instead of data(): <li>{string(doc($xml)/prefix:catalog/prefix:catalogRef/@xlink:tile)}</li>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.