![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Beginner's questions >Thread Next - Re: Beginner's questions Re: Beginner's questionsTo: NULL Date: 8/2/2007 8:41:00 AM Regarding your first point you can create an HTML/HTA page that will use the iTunes.xml as a source and control the transformation via script, load the XML into a DomDocument, the same with the XSLT and then transform the XML and add the result to the page. There are examples of this in the msxml sdk. As to the actual transform I agree it's made tricky by the non-nested nature of the XML but if you only want those three columns then you just need to apply-templates to key elements and test the value or narrow down the selection with a predicate: <xsl:apply-templates select="key[. = 'Name']"/> <xsl:apply-templates select="key[. = 'Rating']"/> You can then retrieve the first following-sibling: <xsl:value-of select="following-sibling::*[1]"/> -- Joe Fawcett (MVP - XML) http://joe.fawcett.name "Howard Brazee" <howard@b...> wrote in message news:fuq1b3dcorherpd5nqgk1v6mc61t8u483j@4...... > I'm writing an .XSL for the iTunes XML file. > > > Part 1: > My first problem is that C:\Documents and Settings\brazee\My > Documents\My Music\iTunes\iTunes Music Library.xml doesn't have a > style sheet in it, so I copy it and add the following line in it: > <?xml-stylesheet href="myiTunes.xsl" type="text/xsl"?> > > Is there a trick to avoid this? > > Part 2: > > Then the XML is oddly designed. The following is one record: > > <key>1056</key> > <dict> > <key>Track ID</key><integer>1056</integer> > <key>Name</key><string>Gorecki - Symphony 3., op36. 1. Lento. > Sostenuto tranquillo ma catabile</string> > <key>Artist</key><string>Orchestre Philharmonique de Varsovie, > Kazimierez Kord</string> > <key>Composer</key><string>Henryk Mikolaj Gorecki</string> > ... > > When a field is empty, it is is missing. > > So I tried this: > <xsl:template match='dict'> > <xsl:for-each select='key'> > <xsl:if test='. = "Name"'> > <br/>Name:  <xsl:value-of select='../string[position() = > 1]'/> > </xsl:for-each><br/> > </xsl:template> > > This works because "Name" always exists in position 1. > > But if I want rating, I need to find out what position it is at. It > may be 13, or it may be 12 or it may be something else, depending on > how many fields are defined for that record. > > My desired output here is: > > Sequence Name Rating > 1 My Song 3 > 2 My Other Song (blank) > > Where it didn't find the field "Rating" in this record. > > How should I create the XSL to do this? > > > > | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
