Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

xpath - Xquery How to check the value of a element with an attribute

I am really getting mad because I just don't know how to solve this X-Path/ X-Query problem

I have a Lido-File. Let assume this:

    <lido:actorInRole>
                     <lido:actor lido:type="Person">
                        <lido:actorID lido:type="d-nb.info" lido:source="http://d-nb.info/gnd/116001313">116001313</lido:actorID>
                        <lido:actorID lido:type="uuid">2ca86edd-6113-4133-a86e-dd61135133ae</lido:actorID>
                        <lido:nameActorSet>
                           <lido:appellationValue lido:pref="preferred">Abel, Alfred</lido:appellationValue>
                        </lido:nameActorSet>
                        <lido:vitalDatesActor>
                           <lido:earliestDate>1879</lido:earliestDate>
                           <lido:latestDate>1937</lido:latestDate>
                        </lido:vitalDatesActor>
                        <lido:genderActor>m?nnlich</lido:genderActor>
                     </lido:actor>
                       <lido:actor lido:type="Person">
                        <lido:actorID lido:type="d-nb.info" lido:source="http://d-nb.info/gnd/118501402">118501402</lido:actorID>
                        <lido:actorID lido:type="uuid">2e00b761-d766-47c5-80b7-61d76607c58d</lido:actorID>
                        <lido:nameActorSet>
                           <lido:appellationValue lido:pref="preferred">Albers, Hans</lido:appellationValue>
                        </lido:nameActorSet>
                        <lido:vitalDatesActor>
                           <lido:earliestDate>1891</lido:earliestDate>
                           <lido:latestDate>1960</lido:latestDate>
                        </lido:vitalDatesActor>
                        <lido:genderActor>m?nnlich</lido:genderActor>
                     </lido:actor>
   </lido:actorInRole>

I am using a index.qxl where I am asking for the value of //lido:actorID[@lido:type="uuid"]

So i want to iterate through the these elements and check if the number of the number of //lido:actorID[@lido:type="uuid"] is 2ca86edd-6113-4133-a86e-dd61135133ae or something else.

like "is the content of the object lido:actor withe the attribut lido:type containing the value 'uuid' 2ca86edd-6113-4133-a86e-dd61135133ae or not?. if yes, then give me the ancestor of this object. if not, do nothing"

How can I achieve this?!

Again. I DONT WANT THE VALUE OF lido:type!!!! I want the content of the whole element. The ID Number!! And let this checked via an if-else which is nested in a for loop.

Please I really need help!!!

question from:https://stackoverflow.com/questions/65946909/xquery-how-to-check-the-value-of-a-element-with-an-attribute

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming that you want to select the node

<lido:actor lido:type="Person">...

you can use the following XPath-1.0 expression

//lido:actor[lido:actorID[@lido:type='uuid']='2ca86edd-6113-4133-a86e-dd61135133ae']

It should give you the lido:actor node which has a child <actorID> with a lido:type attribute with the desired value.

You can use this XPath-1.0 expression in an <xsl:if test='...'> or a template's match rule. In both cases the content of the matched node can be retrieved with <xsl:copy-of select="." />.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...