Hi Danny,

 

The XML documents in my case can have different structures so I will not
know the element name or attribute name to use in the function

"cts:element-attribute-word-query"

 

Thanks,

Pradeep Maddireddy

________________________________

From: Danny Sokolsky [mailto:[email protected]] 
Sent: Tuesday, December 30, 2008 5:23 PM
To: Pradeep Maddireddy; General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] search elements and attributes of
alldocuments

 

Hi Pradeep,

 

You can do a cts:search with a cts:word-query to find the text in text
nodes in your document, which will take care of your Doc1 case,
regardless of what element the text is in.  For the Doc2 case, you need
to use a cts:element-attribute-word-query and specify the element and
attribute.  For the attributes, you need to specify each
element-attribute pair that you want to search through.  If you combine
the 2 queries with an or-query, then you can search for them both at the
same time.  Something like:

 

let $word := "apple"

return

cts:search(doc(), cts:or-query(( cts:word-query($word), 

  cts:element-attribute-word-query(xs:QName("name"), 

           xs:QName("category"), $word) )) )

 

-Danny

 

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Pradeep
Maddireddy
Sent: Tuesday, December 30, 2008 1:57 PM
To: [email protected]
Subject: [MarkLogic Dev General] search elements and attributes of
alldocuments

 

Hi..!

 

How can we write an Xquery function to find the documents (XML documents
with different structures) that have the word "fruit" in them either as
an element or attribute? 

 

For example say Doc1 has the following content

 

<root>

<Category>fruit</Category>

<name>Apple</name>

</root>

 

Doc2 has the following content

 

<root>

<name category="fruit">Apple</name>

</root>

 

Both the documents should be selected as the first document has "fruit"
as element and second document has "fruit" as an attribute.

 

Thanks in advance.

 

Regards,

Pradeep Maddireddy

 

 

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to