|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Transforming Key/Value pairs with XSL (i.e iTunes xml file)
I'm trying to figure out the best way to transform an XML file that has the structure of Key value pairs. In particular, any programs on MAC OSX that support xml export. For those of you not familar, something like my iTunes library would look like this:
PHP Code:
Now rather than the XML file being structured like I would think, (i.e) PHP Code:
How can effectively display the information the way that it is using XSL? Is it possible to use XSL to display the key/value pairs? Should I write a better XML export for each application that structures the data more representative of how it should be? A side question to this, is why is the data represented like this in Apple's export? Is it really a better way to store the data? Or is it just that they are lazy and didn't want to customize the XML export to each application? Rather than just have an export that turns the datafile of an application into an XML file so you can do more with it? Anyway, thanks for your time and any help would be greatly appreciated. |
|
#2
|
|||
|
|||
|
Yes, it's a cop out. Not only that, but it's really sucky xml. Here's an xsl file will turn it into non-sucky (but still copped-out) xml.
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/dict/dict/key">
<element key="{.}">
<xsl:value-of select="following-sibling::node()" />
</element>
</xsl:template>
<xsl:template match="text()">
<!-- skip all text -->
</xsl:template>
</xsl:stylesheet>
The problem with turning it directly into a format similar to what you described is that some of the element keys contain spaces, so they can't be element names. You should be able to either 1) perform a second transform that structures the data properly or 2) use the same technique with some logic thrown in that generates appropriate element names. Apple really should provide better export capability. The format they have now is rather difficult to work with. There's no apparent relationship between keys and values, since XML (generally) only understands heirarchies. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Transforming Key/Value pairs with XSL (i.e iTunes xml file) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|