Altova Mailing List Archives


Re: Beginner's questions

From: "Joe Fawcett" <joefawcett@---------.------>
To: 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: &#160;<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?
>
>
>
> 

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.