2

Given this xml:

<mets:techMD ID="techMD014">
    <mets:mdWrap MDTYPE="PREMIS:OBJECT">
        <mets:xmlData>
            <premis:object
                    xsi:type="premis:file"
                    xsi:schemaLocation="info:lc/xmlns/premis-v2
                    http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd">
                <premis:objectIdentifier>
                    <premis:objectIdentifierType
                     >filepath</premis:objectIdentifierType>
                    <premis:objectIdentifierValue
                     >bib1234_yyyymmdd_99_x_performance.xml</premis:objectIdentifierValue>
                </premis:objectIdentifier>
            </premis:object>
        </mets:xmlData>
    </mets:mdWrap>
</mets:techMD>
<mets:techMD ID="techMD015">
    <mets:mdWrap MDTYPE="PREMIS:OBJECT">
        <mets:xmlData>
            <premis:object
                    xsi:type="premis:representation"
                    xsi:schemaLocation="info:lc/xmlns/premis-v2
                    http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd">
                <premis:objectIdentifier>
                    <premis:objectIdentifierType
                     >local</premis:objectIdentifierType>
                    <premis:objectIdentifierValue
                     >bib1234_yyyymmdd_99_x</premis:objectIdentifierValue>
                </premis:objectIdentifier>
            </premis:object>
        </mets:xmlData>
    </mets:mdWrap>
</mets:techMD>

I would like to make a xpath query that takes both index and attribute into account. I.e can I combine these two into ONE query? (Its the stuff around the "object" element Im interested in):

//techMD/mdWrap[
   @MDTYPE=\'PREMIS:OBJECT\'
]/xmlData//object[1]/objectIdentifier/objectIdentifierValue

//techMD/mdWrap[
   @MDTYPE=\'PREMIS:OBJECT\'
]/xmlData//object[
   @xsi:type=\'premis:file\'
]/objectIdentifier/objectIdentifierValue

Thanks!

1 Answer 1

5

Just replace according part to:

object[@xsi:type='premis:file'][1]

if you want first object of those who have a given xsi:type value or

object[1][@xsi:type='premis:file']

if you want the first object, providing it has a given xsi:type value.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 Correct answer. Last predicate would be equal to [position()=1 and @xsi:type='premis:file']
@Alejandro. Yes. And in fact would be faster in some implementations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.