Hi Pradeep,

 

In order to search for content in attributes, you will need to know the
element-attribute pairs to search.  I would suggest one of two things:
either restructure your XML so that you know the attributes, or keep
track of all of your element-attribute pairs.  One way to keep track of
the element-attribute pairs is to have some sort of content processing
pipeline that looks through all of your content and then keeps a list
(in a document, for example) of the element-attribute pairs.  You can
then use that list to construct the cts:element-attribute-word-query for
your or-query (note that the QNames can be lists of QNames in
cts:element-attribute-word-query, so you can create a single
cts:element-attribute-word-query that covers all of your or'ed
possibilities).  Partly this will depend on how many unique pairs there
are, but I think for most content sets it will work quite well.

 

-Danny

 

 

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

 

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