[MarkLogic Dev General] Attribute value based xquery

Ian Small ian at marklogic.com
Fri Aug 10 10:08:57 PDT 2007


you can use an xpath:
 
/html/body/element[@attr1="atval11" and @attr2="atval12"]
 
that will actually return the individual matching elements.  changing
the predicate can change what is returned.
 
you can use a search:
 
cts:search(/html,
cts:and-query((cts:element-attribute-value-query(xs:QName("element"),
xs:QName("attr1"),
"atval11"),cts:element-attribute-value-query(xs:QName("element"),
xs:QName("attr2"), "atval12"))))
 
with the slight caveat that as written, this will not insist that the
attr1 and attr2 attributes have the same element parent.
 
in both cases, you need to watch out for namespaces.  these queries will
match the xml you have provided, but the xml you have provided is not in
the xhtml namespace, which yours may well be.  generally the reason for
xpaths or cts:search() not matching something that it seems like it
should match is namespace mismatches...
 
ian

________________________________

From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of Devadoss P
Sent: Friday, August 10, 2007 5:11 AM
To: general at developer.marklogic.com
Subject: [MarkLogic Dev General] Attribute value based xquery


Hi,
 
I am having problem in generating xquery to search on attribute value of
html element.  Can anyone comeacross this situation?
 
<html>
<body>
<element1 attr1="atval11" attr2="val12" />
<element1 attr1="atval21" attr2="val22" />
<element1 attr1="atval31" attr2="val32" />
<element1 attr1="atval41" attr2="val42" />
</body>
</html> 
 
I want to get documents that satisfy "attr1" value = "atval11" and
attr2="val12".
 
I used cts;element-attribute-value-query but it doesn't return expected
value for html documents.
 
Appreciate your feedback,
 
~Dev~
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20070810/9d8120db/attachment.html


More information about the General mailing list