kvnmck18 Posted September 21, 2006 Share Posted September 21, 2006 I had about 500 CDs stolen from my house 2 weeks ago now I am filing a my insurance report...I have to list all the CDs stolen. I have about half of my CDs on my Itunes, to save time I was goign to use the XML of the Itunes Catalogue. I have already started doing this but there is a problem...Pretty much everything is referred to as "key", "string", or "interger"...but when I made my XSL it only selected the values of the first "keys"/ect. is there anyway to get all the "keys" under the selected value of "plist/dict/dict/dict"?Here's my XSL so far: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><table><xsl:for-each select="plist/dict/dict/dict"><tr><td><xsl:value-of select="string"/></td></tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet> I can't put the XML....it's way to long, if you think you need it I'll post a snipit.I hope you can help, this would save me so much time....I hope I explained this well. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="plist/dict/dict/dict"><html><body><table><xsl:for-each select="/"><tr><td><xsl:value-of select="string"/></td></tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet> I've tried this too...I think this is more on the way.Here's the /dict of just one song: <dict> <key>Track ID</key><integer>44</integer> <key>Name</key><string>Agenda Suicide</string> <key>Artist</key><string>The Faint</string> <key>Album</key><string>Danse Macabre</string> <key>Genre</key><string>Alternative & Punk</string> <key>Kind</key><string>AAC audio file</string> <key>Size</key><integer>3850776</integer> <key>Total Time</key><integer>238515</integer> <key>Disc Number</key><integer>1</integer> <key>Disc Count</key><integer>1</integer> <key>Track Number</key><integer>1</integer> <key>Track Count</key><integer>9</integer> <key>Year</key><integer>2001</integer> <key>Date Modified</key><date>2004-11-16T02:06:10Z</date> <key>Date Added</key><date>2004-11-16T02:05:10Z</date> <key>Bit Rate</key><integer>128</integer> <key>Sample Rate</key><integer>44100</integer> <key>Play Count</key><integer>5</integer> <key>Play Date</key><integer>-1102521467</integer> <key>Play Date UTC</key><date>2005-02-28T19:30:29Z</date> <key>Location</key><string>/The%20Faint/Danse%20Macabre/01%20Agenda%20Suicide.m4a/</string> <key>File Folder Count</key><integer>4</integer> <key>Library Folder Count</key><integer>1</integer> </dict> I need the <key>Artist</key><string>The Faint</string><key>Album</key><string>Danse Macabre</string><key>Year</key><integer>2001</integer>....oh and I have thought about attributes to distinguish them...but if you think about it that'd take a year to do (that's 3 times 500 at min) Link to comment Share on other sites More sharing options...
boen_robot Posted September 23, 2006 Share Posted September 23, 2006 Are the keys always in this order? I mean, is the artist for example always in the 6th element (3rd key, second) place? If so, then the easyest way to go is position(). Something like: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><table><thead><tr><xsl:for-each select="plist/dict/dict/dict/*[position()=5 or position()=7 or postion()=25]"><td><xsl:value-of select="."/></td></xsl:for-each></tr></thead><tbody><xsl:for-each select="plist/dict/dict/dict"><tr><xsl:for-each select="*[position()=6 or position()=8 or postion()=26]"><td><xsl:value-of select="."/></td></xsl:for-each></tr></xsl:for-each><tbody></table></body></html></xsl:template></xsl:stylesheet> If you weren't in a hurry, I would have tryed to devise a more flexible solution, but if this works for you, then such is useless right now anyway. Link to comment Share on other sites More sharing options...
kvnmck18 Posted September 25, 2006 Author Share Posted September 25, 2006 They all follow that order. I'll give that a try. Link to comment Share on other sites More sharing options...
kvnmck18 Posted September 25, 2006 Author Share Posted September 25, 2006 That worked~ But, now is it possible to do this but limit the result... so there is no repeat with the position 6, 8, 26?PS- You are by far the best XML expert in the world. Nothing stumps you.YOU ROCK Link to comment Share on other sites More sharing options...
boen_robot Posted September 27, 2006 Share Posted September 27, 2006 Well, you can always add a conditional in the cell like this: <xsl:for-each select="*[position()=6 or position()=8 or postion()=26]"><td><xsl:if test="whatever you want to exclude by"><xsl:value-of select="."/></xsl:if></td> But that's probably not the most comfy and flexible thing. And it still relies on position() too.Without it... hmm... I'm not sure, but I think this might work just as well: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><table><thead><tr><xsl:for-each select="plist/dict/dict/dict/key[.='Artist' or .='Album' or .='Year']"><td><xsl:value-of select="."/></td></xsl:for-each></tr></thead><tbody><xsl:for-each select="plist/dict/dict/dict"><tr><xsl:for-each select="key[.='Artist' or .='Album' or .='Year']"><td><xsl:value-of select="following-sibling::*[position()=1]"/></td></xsl:for-each></tr></xsl:for-each><tbody></table></body></html></xsl:template></xsl:stylesheet> And you can add new columns by just adding them to the "key[.=Artist' or .='Album' or .='Year]" parts. And adding filters to them is just as easy. If you want to add a filter only for specific key, you would make it like: key[boolean(.='Artist' and string(following-sibling::*[position()=1])='whatever artist you want to filter by') or .='Album' or .='Year'] And if you want to add overall filter (applicable to any key) then.... press any key... haha.... just little computer joking . Anyway... if you want any key filter, then use the boolean() function over all keys, not just one: key[boolean(.='Artist' or .='Album' or .='Year') and string(following-sibling::*[position()=1])='whatever you want to filter by'] P.S. Actually, there are still a few things that I can't handle properly with XSLT. XPath axes are one of those things, so I'll be a little surprised if my above code works flawlessly. Link to comment Share on other sites More sharing options...
kvnmck18 Posted September 28, 2006 Author Share Posted September 28, 2006 Wonderful. What don't you know? You aren't human. hahaThank you so much. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now