Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:31:45+00:00 2026-05-24T16:31:45+00:00

I am writing xsl stylesheet to extract information from iTunes Music Library. xml file.

  • 0

I am writing xsl stylesheet to extract information from iTunes Music Library. xml file.

I want to store track information of playlists in an array and later iterate over them to get more information. I am confused how to store values in an array in xslt?

My attempt is here:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" /> 
    <xsl:template match="/"> 

    <xsl:variable name="tracks"
           select="plist/dict/array/dict[integer[preceding-sibling::key[1]='Playlist ID']=6711]/array/dict/integer[preceding-sibling::key[1]='Track ID']" />

    <!-- I want to iterate over that array outside for-each loop and gather more information, The below code is not working.-->

   <xsl:for-each select="$tracks">
  <xsl:value-of select="." />
  <xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/integer[preceding-sibling::key[1]='Track ID']" />
  <xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/string[preceding-sibling::key[1]='Name']" />
  <xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/string[preceding-sibling::key[1]='Total Time']" />
  <xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/string[preceding-sibling::key[1]='Location']" />
  <xsl:text>&#xa;</xsl:text>
</xsl:for-each>


    </xsl:template>
    </xsl:stylesheet>

A typical Track Ids which are populated in array variable “tracks”, are represented in below manner in itunes list. I want to list Name, Location, time infor for each Track Ids stored in the array. Something wrong with my conditions.

<plist>
  <dict>
    <dict>
      <dict>
        <key>Track ID</key>
        <integer>1633</integer>
        <key>Name</key>
        <string>Right here</string>
        <key>Kind</key>
        <string>MPEG audio file</string>
        <key>Total Time</key>
        <integer>358870</integer>
        <key>Location</key>
        <string>/Users/rakesh/Music/iTunes/iTunes%20Media/Music/track1633.mp3</string>
      </dict>
      <dict> 
        <!-- Next Track info -->
      </dict>
    </dict>
  </dict>
</plist>

Here I am stuck. Can any XSLT experts here to help me out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:31:45+00:00Added an answer on May 24, 2026 at 4:31 pm

    You could just create a variable and populate its results with an XPath expression all in one go rather than interate through to build it.

    <xsl:variable name="tracks"
      select="plist/dict/array/dict[integer[preceding-sibling::key[1]='Playlist ID']=6711]/array/dict/integer[preceding-sibling::key[1]='Track ID']" />
    

    Alternatively you could use xsl:keys at the begining of your document, I’m assuming that the path to the track information is /plist/dict/array/dict with the first dict key being Tracks

    <xsl:key 
            name="playlists"
            match="plist/dict/array/dict/array/dict/integer[preceding-sibling::key[1]='Track ID']"
            use="../../../integer[preceding-sibling::key[1]='Playlist ID']"
    />
    <xsl:key 
           name="tracks" 
           match="/plist/dict/array[preceding-sibling::key[1]='Tracks']/dict"
           use="integer[preceding-sibling::key[1]='Track ID']"
    />
    

    This allows you to do key('playlists','4555') to return all the trackids associated with playlist id 4555 and also key('tracks','1234') to get the dict object associated with track id 1234

    You can then combine the two together to do

    <xsl:variable "mytracks" select="key('tracks',key('playlists','6711'))" />
    

    That will set $mytracks equal to the array of dict objects for the tracks in playlist 6711. It aslo has the benefits of the speed enhancement granted by xsl:key

    EDIT UPDATE—-

    I’m guessing you are trying to make a CSV from this so this code should do that

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
      <xsl:output method="text" />
      <xsl:key
        name="playlists"
        match="plist/dict/array/dict/array/dict/integer[preceding-sibling::key[1]='Track ID']"
        use="../../../integer[preceding-sibling::key[1]='Playlist ID']"
      />
      <xsl:key
        name="tracks"
        match="/plist/dict/dict/dict"
        use="integer[preceding-sibling::key[1]='Track ID']"
      />
    
      <xsl:template match="/">
        <xsl:variable name="myplaylist" select="'6711'"/>
        <xsl:for-each select="key('tracks',key('playlists',$myplaylist))">
          <xsl:value-of select="integer[preceding-sibling::key[1]='Track ID']"/>
          <xsl:text>,</xsl:text>
          <xsl:value-of select="string[preceding-sibling::key[1]='Name']"/>
          <xsl:text>,</xsl:text>
          <xsl:value-of select="integer[preceding-sibling::key[1]='Total Time']"/>
          <xsl:text>,</xsl:text>
          <xsl:value-of select="string[preceding-sibling::key[1]='Location']"/>
          <xsl:text>&#xa;</xsl:text>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>
    

    to match a different playlist id just change the value of myplaylist

    –EDIT Version without xsl:key ,again just alter the value of the myplaylist variable

    –EDIT Now mofified to original sort order of playlist
    –EDIT Attempt to work around Qt Limitations

      <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
      <xsl:output method="text" />
    
      <xsl:template match="/">
        <xsl:variable name="myplaylist" select="'4053'"/>
        <xsl:variable name="playlist_tracks" select="/plist/dict/array/dict[integer[preceding-sibling::key[1]='Playlist ID']=$myplaylist]/array/dict/integer[preceding-sibling::key[1]='Track ID']" />
    
        <xsl:for-each select="$playlist_tracks">
          <xsl:variable select="." name="current" />
          <xsl:for-each select ="/plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']=$current]" >
            <xsl:value-of select="integer[preceding-sibling::key[1]='Track ID']"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="string[preceding-sibling::key[1]='Name']"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="integer[preceding-sibling::key[1]='Total Time']"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="string[preceding-sibling::key[1]='Location']"/>
            <xsl:text>&#xa;</xsl:text>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a stylesheet in xsl (version 2.0) I want to know how could
I have a simple XSL file which looks like: <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0>
i have xml file such as following. <?xml-stylesheet type='text/xsl' href='AdditionalLogInfo.xsl'?> <Logs> <Log TestName=EwireDepositTests Date=Oct
Iam writing a program to call php from xsl but I need to store
I am writing a Page with XML Only. No XSL is being. everything is
I want to write an xslt to transform one xml file to another. The
I'm writing XSL and I want to make comments throughout the code that will
I am writing an XSL file and need to convert the Central time to
I've just received an absoultely mad task of writing an xsl file that should
Does anyone know of a library that is capable of generating XSL-FO from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.