1

Given this XML:

<mets:mets>
 <mets:fileSec>
   <mets:fileGrp ID="fileGrp001" USE="image/dynamic">
  <mets:file ID="filebib4112678_18760203_1_24_0001_m.jp2" MIMETYPE="image/jp2" SIZE="5308416"
    CREATED="2009-11-10T00:00:00" USE="image/dynamic" ADMID="techMD001"
    CHECKSUM="c07f516d77d8a5ca452775d489ffe78c" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0001_m.jp2"/>
  </mets:file>
  <mets:file ID="filebib4112678_18760203_1_24_0002_m.jp2" MIMETYPE="image/jp2" SIZE="5308416"
    CREATED="2009-11-10T00:00:00" USE="image/dynamic" ADMID="techMD002"
    CHECKSUM="6497ceb7a8477fbe9ba4ff9e6e57999f" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0002_m.jp2"/>
  </mets:file>

</mets:fileGrp>
<mets:fileGrp ID="fileGrp002" USE="text/alto">
  <mets:file ID="filebib4112678_18760203_1_24_0001_alto.xml" MIMETYPE="text/xml" SIZE="1114112"
    CREATED="2009-11-10T00:00:00" USE="text/alto" ADMID="techMD005"
    CHECKSUM="e391852693f78d2eb024caf6dbdb97c6" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0001_alto.xml"/>
  </mets:file>
  <mets:file ID="filebib4112678_18760203_1_24_0002_alto.xml" MIMETYPE="text/xml" SIZE="1114112"
    CREATED="2009-11-10T00:00:00" USE="text/alto" ADMID="techMD006"
    CHECKSUM="e391852693f78d2eb024caf6dbdb97c6" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0002_alto.xml"/>
  </mets:file>

   </mets:fileGrp>
  </mets:fileSec>
</mets:mets>

This expression :

/mets/fileSec/fileGrp[2]/file[2]/@ADMID

gives the result "techMD006"

However, I would like to get the same result using something like this expression/query:

/mets/fileSec//file[4]/@ADMID

I.e I don't want to bother about the fileGrp element, since it makes things more complicated. Unfortunately the expression above didn't work..

Does anyone know how to make such an expression?

thanx!

Jojje
  • 1,749
  • 3
  • 25
  • 44
  • Check this out, I think you'll be able to query for your file element and then just select the index you want...http://stackoverflow.com/questions/4007413/xpath-query-to-get-nth-instance-of-an-element – Sam Trost Mar 25 '11 at 15:47
  • One of the many duplicates of this FAQ: http://stackoverflow.com/questions/4007413/xpath-query-to-get-nth-instance-of-an-element –  Mar 26 '11 at 01:00

1 Answers1

1

Your expression retrieves all file elements that are a descendant of /mets/fileSec and are the fourth child of their parent:

/mets/fileSec//file[4]/@ADMID

But you have no such elements. What you want is to retrieve all file elements that are a descendant of /mets/fileSec and then take the fourth one. Use this:

(/mets/fileSec//file)[4]/@ADMID
Wayne
  • 59,728
  • 15
  • 131
  • 126