문제

I have a problem dealing with xquery, I have different type of nodes at the same level. I need to display an xquery depending on the node. Following is the example

   <head>
         <type1>
              <name>abc</name>
         </type1>
         <type2>
               <name>def</name>
               <type1>
                      <name>efg</name>
               </type1>
         </type2>
   </head>

Now I would like to perform an xquery where the name tag has to be checked. like if name is "def" then result should be

  <type1>
                <name> efg </name>
   </type1>

Can you please direct me to work on this.

도움이 되었습니까?

해결책

This cone be done in a simple XPath (XPath is a subset of XQuery). The expression will be:

//*[name = 'def']/type1

This searches for all elements with a child element named name equal to def and returns the type1 element. Depending on your actual data you might want to change * (a wildcard operator) to type2, if you just want to search in type2 elements. This is not quite clear from your question.

You might also want to check the basics of XPath/XQuery as this is one of the most basic things. So if you intend to spend more time using XPath/XQuery you should make yourself more familiar with the language.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top