title: XSLT 2.0: How to iterate over stored values of an array inside a for-each loop with conditional check?
body: <p>I am writing xsl stylesheet to extract information from iTunes Music Library. xml file.</p>
  
  <p>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?</p>
  
  <p>My attempt is here:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
      &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="text" /&gt; 
      &lt;xsl:template match="/"&gt; 
  
      &lt;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']" /&gt;
  
      &lt;!-- I want to iterate over that array outside for-each loop and gather more information, The below code is not working.--&gt;
  
     &lt;xsl:for-each select="$tracks"&gt;
    &lt;xsl:value-of select="." /&gt;
    &lt;xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/integer[preceding-sibling::key[1]='Track ID']" /&gt;
    &lt;xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/string[preceding-sibling::key[1]='Name']" /&gt;
    &lt;xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/string[preceding-sibling::key[1]='Total Time']" /&gt;
    &lt;xsl:value-of select="plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']="."]/string[preceding-sibling::key[1]='Location']" /&gt;
    &lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;
  &lt;/xsl:for-each&gt;
  
  
      &lt;/xsl:template&gt;
      &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>&lt;plist&gt;
    &lt;dict&gt;
      &lt;dict&gt;
        &lt;dict&gt;
          &lt;key&gt;Track ID&lt;/key&gt;
          &lt;integer&gt;1633&lt;/integer&gt;
          &lt;key&gt;Name&lt;/key&gt;
          &lt;string&gt;Right here&lt;/string&gt;
          &lt;key&gt;Kind&lt;/key&gt;
          &lt;string&gt;MPEG audio file&lt;/string&gt;
          &lt;key&gt;Total Time&lt;/key&gt;
          &lt;integer&gt;358870&lt;/integer&gt;
          &lt;key&gt;Location&lt;/key&gt;
          &lt;string&gt;/Users/rakesh/Music/iTunes/iTunes%20Media/Music/track1633.mp3&lt;/string&gt;
        &lt;/dict&gt;
        &lt;dict&gt; 
          &lt;!-- Next Track info --&gt;
        &lt;/dict&gt;
      &lt;/dict&gt;
    &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>Here I am stuck. Can any XSLT experts here to help me out? </p>