min - XPath 1.0 - How can I get the minimum value in my selection of elements? -
example of file (exercise based on itunes xml file) :
<plist version="1.0"> <dict> <key>major version</key><integer>1</integer> <key>minor version</key><integer>1</integer> ... <dict> <key>219</key> <dict> <key>track id</key><integer>219</integer> <key>name</key><string>ruby</string> ... <key>track number</key><integer>1</integer> <key>track count</key><integer>11</integer> <key>year</key><integer>2010</integer> <key>date modified</key><date>2010-08-28t10:16:04z</date> <key>date added</key><date>2010-08-30t19:40:27z</date> ... </dict> <key>243</key> <dict> <key>track id</key><integer>223</integer> <key>name</key><string>no more mr nice guy</string> ... <key>track number</key><integer>1</integer> <key>track count</key><integer>11</integer> <key>year</key><integer>2005</integer> <key>date modified</key><date>2010-08-28t10:17:54z</date> <key>date added</key><date>2010-08-30t20:14:13z</date> ... </dict>
(i need use xpath 1.0) need name of oldest track(s) (comparing element year) don't know how min year, after have done request year element:
/plist/dict/dict/dict/integer[./preceding-sibling::key="year"][1]
is there can me?
thanks!
i know of no xpath 1.0 solution. xpath 1.0 missing crucial functionality fn:min()
, order by
, etc.
here's xpath 2.0 solution, in case can upgrade:
/plist//dict [ key[. ="year"]/following-sibling::integer/xs:integer(.) eq min(../dict/key[. ="year"]/following-sibling::integer/xs:integer(.)) ] /key[. eq "name"]/following-sibling::string/fn:string()
Comments
Post a Comment