home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
developer.apple.com
/
developer.apple.com.tar
/
developer.apple.com
/
appleapplications
/
SystemReport.dmg
/
flattenplist.xsl
< prev
next >
Wrap
Extensible Markup Language
|
2007-04-14
|
1KB
|
50 lines
<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Flatten a PList into individual string and integer nodes.
Each node is given a key attribute equal to the preceding-sibling key node's value.
This will turn
<array>
<key>a</key>
<string>Alpha</string>
<key>b</key>
<integer>1</integer>
</array>
into
<string key="a">Alpha</string>
<integer key="b">2</integer>
This vastly simplifies the XSL needed to pick out simple values from a property list.
-->
<xsl:template match="plist">
<plist>
<xsl:apply-templates/>
</plist>
</xsl:template>
<!-- flatten dict and array nodes -->
<xsl:template match="dict|array">
<xsl:apply-templates/>
</xsl:template>
<!-- echo string and integer nodes
assign each a key attribute using the value of to the preceeding key node
-->
<xsl:template match="string">
<string key="{preceding-sibling::key[1]}">
<xsl:apply-templates/>
</string>
</xsl:template>
<xsl:template match="integer">
<integer key="{preceding-sibling::key[1]}">
<xsl:apply-templates/>
</integer>
</xsl:template>
<!-- discard all of the key nodes -->
<xsl:template match="key"/>
</xsl:stylesheet>