Counting elements in xsl

Here should go questions about transforming XML with XSLT and FOP.
sxxx
Posts: 6

Counting elements in xsl

Fri Apr 15, 2005 9:05 pm

Hi all,

I would like to know if there is any method for counting the number of times a particular element occurs in a xml program using a xsl stylesheet.
This is the code which i have

Code: Select all

<dict>
      <key>35</key>
      <dict>
         <key>Track ID</key><integer>35</integer>
         <key>Name</key><string>Chiquita</string>
         <key>Artist</key><string>ABBA</string>
         <key>Album</key><string>Gold</string>
         <key>Genre</key><string>Pop</string>
         <key>Kind</key><string>MPEG audio file</string>
         <key>Size</key><integer>6528577</integer>
         <key>Total Time</key><integer>326321</integer>
         <key>Track Number</key><integer>11</integer>
         <key>Track Count</key><integer>19</integer>
         <key>Date Modified</key><date>2001-11-12T14:57:17Z</date>
         <key>Date Added</key><date>2002-10-18T12:31:08Z</date>
         <key>Bit Rate</key><integer>160</integer>
         <key>Sample Rate</key><integer>44100</integer>
         <key>Play Count</key><integer>3</integer>
         <key>Play Date</key><integer>-1148223841</integer>
         <key>Play Date UTC</key><date>2003-09-18T19:24:15Z</date>
         <key>Track Type</key><string>File</string>
         <key>File Type</key><integer>1297106739</integer>
         <key>File Creator</key><integer>1752133483</integer>
         <key>Location</key><string>file://localhost/Volumes/Portable/Music/iTunes/iTunes%20Music/ABBA/Gold/Chiquita.mp3</string>
         <key>File Folder Count</key><integer>-1</integer>
         <key>Library Folder Count</key><integer>-1</integer>
      </dict>
      <key>36</key>
      <dict>
         <key>Track ID</key><integer>36</integer>
         <key>Name</key><string>Dancing Queen</string>
         <key>Artist</key><string>ABBA</string>
         <key>Album</key><string>Gold</string>
         <key>Genre</key><string>Pop</string>
         <key>Kind</key><string>MPEG audio file</string>
         <key>Size</key><integer>4647242</integer>
         <key>Total Time</key><integer>232254</integer>
         <key>Track Number</key><integer>1</integer>
         <key>Track Count</key><integer>19</integer>
         <key>Date Modified</key><date>2001-11-12T14:41:25Z</date>
         <key>Date Added</key><date>2002-10-18T12:31:08Z</date>
         <key>Bit Rate</key><integer>160</integer>
         <key>Sample Rate</key><integer>44100</integer>
         <key>Play Count</key><integer>3</integer>
         <key>Play Date</key><integer>-1148226321</integer>
         <key>Play Date UTC</key><date>2003-09-18T18:42:55Z</date>
         <key>Track Type</key><string>File</string>
         <key>File Type</key><integer>1297106739</integer>
         <key>File Creator</key><integer>1752133483</integer>
         <key>Location</key><string>file://localhost/Volumes/Portable/Music/iTunes/iTunes%20Music/ABBA/Gold/Dancing%20Queen.mp3</string>
         <key>File Folder Count</key><integer>-1</integer>
         <key>Library Folder Count</key><integer>-1</integer>
      </dict>


I need to find the number of artists in the xml code(which is 2)

thanx
george
Site Admin
Posts: 2100

Sat Apr 16, 2005 10:13 am

count(//key[text()='Artist'])

Best Regards,
George

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 2 guests