home *** CD-ROM | disk | FTP | other *** search
/ developer.apple.com / developer.apple.com.tar / developer.apple.com / appleapplications / SystemReport.dmg / flattenplist.xsl < prev    next >
Extensible Markup Language  |  2007-04-14  |  1KB  |  50 lines

  1. <?xml version='1.0' encoding='utf-8' ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.  
  4. <!--
  5.     Flatten a PList into individual string and integer nodes.
  6.     Each node is given a key attribute equal to the preceding-sibling key node's value.
  7.     This will turn
  8.         <array>
  9.             <key>a</key>
  10.             <string>Alpha</string>
  11.             <key>b</key>
  12.             <integer>1</integer>
  13.         </array>
  14.     into
  15.         <string key="a">Alpha</string>
  16.         <integer key="b">2</integer>
  17.     
  18.     This vastly simplifies the XSL needed to pick out simple values from a property list.
  19. -->
  20.  
  21. <xsl:template match="plist">
  22.     <plist>
  23.     <xsl:apply-templates/>
  24.     </plist>
  25. </xsl:template>
  26.  
  27. <!-- flatten dict and array nodes -->
  28. <xsl:template match="dict|array">
  29.     <xsl:apply-templates/>
  30. </xsl:template>
  31.  
  32. <!-- echo string and integer nodes
  33.     assign each a key attribute using the value of to the preceeding key node
  34.     -->
  35. <xsl:template match="string">
  36.     <string key="{preceding-sibling::key[1]}">
  37.         <xsl:apply-templates/>
  38.     </string>
  39. </xsl:template>
  40. <xsl:template match="integer">
  41.     <integer key="{preceding-sibling::key[1]}">
  42.         <xsl:apply-templates/>
  43.     </integer>
  44. </xsl:template>
  45.  
  46. <!-- discard all of the key nodes -->
  47. <xsl:template match="key"/>
  48.  
  49. </xsl:stylesheet>
  50.