0

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 to use XPath 1.0) I need to get the name of the oldest track(s) (comparing the element Year) But I don't know how to get the min year, after have done the request to get all the year element:

/plist/dict/dict/dict/integer[./preceding-sibling::key="Year"][1]

Is there anyone who can help me?

Thanks!

Zephou
  • 11
  • 2

2 Answers2

0

I know of no XPath 1.0 solution. XPath 1.0 is missing crucial functionality like fn:min(), order by, etc.

Here's an XPath 2.0 solution, in case you 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()
joemfb
  • 3,056
  • 20
  • 19
0

Many (but not all) XSLT processors support part or all of the EXSLT extension function library. That includes both miniumum and lowest functions. See http://exslt.org/math/functions/min/

Without EXSLT, you'd need to use a named template as a subroutine. The EXSLT page illustrates that too.

keshlam
  • 7,931
  • 2
  • 19
  • 33