[xsl] Improve templates for different identification & rendering of same name XML elements differently based on location in tree

Subject: [xsl] Improve templates for different identification & rendering of same name XML elements differently based on location in tree
From: "Alex S as.signup@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Oct 2017 19:56:32 -0000
Improve templates for different identification & rendering of same name XML
elements differently based on location in tree

Details about the original Springboard .plist XML structure is outlined &
attached below:
http://iky1e.tumblr.com/post/11704062690/springboard-icon-layouts-iconstatepl
ist

I simplified matches, by replacing few "repeating name" elements with
"distinct" names
- Root: <plist> - remains as it is
- Outer <dict> by <all> - Represents all: Pages, Folders, Apps
-- 1st level <array> by <pages>
--- 2nd level <array> by <page>
----- Inner: <dict> remains same - Represents Folders inside Pages
XSL - Leverages the modified elements to create diagnostic dashboard

Some Flaws/ Gaps:
- Need help to rewrite the templates with more XSL knowledge (havent coded in
10 yrs) without needing the above "substitutions"
- Need help to apply/ format "non folder" Apps <strings> differently than
"folder" apps
- Need help to iterate Page Numbers Count - Represented by <page> element

XML Sample File + XSLT

https://www.dropbox.com/sh/1m6qmhrrfxze5kj/AACdkK9HRQS7PXahZeX_uMC_a?dl=0


XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>
<xsl:template match="/">
<html>
<head>
<title>X</title>
<!-- <link rel="stylesheet" href="style.css" type="text/css"></link> -->
<link rel="stylesheet" href="css/style.css" type="text/css"/>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="all">
<!-- Enter ALL
<br/> -->
<!-- Button Bar only -->
<ul>
<!-- <xsl:comment>Test Comment KC</xsl:comment><span>TEST Call KC</span> -->
<xsl:call-template name="KeyCategory"/>
<!-- <xsl:comment>Test Comment FSDN</xsl:comment><span>TEST Call FSDN</span>
-->
<!-- <xsl:call-template name="FolderStringDisplayName"></xsl:call-template>
-->
<xsl:apply-templates select="array"/>
<!-- Apply to & Process Items under Button Bar -->
</ul>
<!-- Button Bar only -->
<xsl:apply-templates select="pages"/>
<!-- Apply to & Process Items under Pages -->
</xsl:template>
<xsl:template match="pages">
<xsl:comment>Enter PAGES</xsl:comment>
<xsl:apply-templates/>
<xsl:comment>Exit PAGES</xsl:comment>
</xsl:template>
<xsl:template match="page">
<xsl:comment>Enter PAGE</xsl:comment>
<ul>
<h2>Pg: <xsl:value-of select="./attribute::num"/>
</h2>
<li>
<input type="checkbox">
<xsl:attribute name="checked">checked</xsl:attribute>
</input>
<i/>
<h2>Folder 1</h2>
<p>Apps 1 </p>
</li>
<!--
  <li>
    <input type="checkbox"><xsl:attribute
name="checked">checked</xsl:attribute></input>
    <i></i>

    <h2>Folder 2</h2>
    <p>Apps 2</p>
-->
<xsl:apply-templates/>
</ul>
<xsl:comment>Exit PAGE</xsl:comment>
</xsl:template>
<xsl:template match="dict">
<!-- Enter Dict
<br/> -->
<!--
<xsl:call-template name="KeyCategory"></xsl:call-template>
<xsl:call-template name="FolderStringDisplayName"></xsl:call-template>
-->
<li>
<input type="checkbox">
<xsl:attribute name="checked">checked</xsl:attribute>
</input>
<i/>
<!--<h2>Folder 1</h2> -->
<h2>
<xsl:value-of select="./string[1]"/>
</h2>
<p>Apps: </p>
<xsl:apply-templates select="array"/>
</li>
</xsl:template>
<xsl:template match="array">
<!-- Enter Array
<br/> -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="string">
<!-- AppName -->
<!--<p>App: <span style="color:#0000ff"><xsl:value-of select="."/></span></p>
-->
<p>
<span>
<xsl:value-of select="."/>
</span>
</p>
</xsl:template>
<!--
<xsl:template match="string">
<xsl:apply-templates select="//*[not(ancestor::dict)]"/>
</xsl:template>
-->
<xsl:template name="KeyCategory">
<h2>
<b>KC: </b>
<span style="color:#ff0000">
<xsl:value-of select="./key[1]"/>
</span>
</h2>
</xsl:template>
<xsl:template name="FolderStringDisplayName">
<b>FolderName: </b>
<span style="color:#ff0000">
<b>
<xsl:value-of select="./string[1]"/>
</b>
</span>
</xsl:template>
</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2013 sp1 (http://www.altova.com) by o;?AX (AX) -->
<plist version="1.0">
<all orig="dict">
<!-- Outer <dict> replaced by <all> represents ButtonBar + ALL Pages -->
<key>buttonBar</key>
<array>
<string>com.apple.MobileSMS</string>
<string>com.apple.mobilemail</string>
<string>com.apple.mobilesafari</string>
<dict>
<key>iconLists</key>
<array>
<array>
<string>com.guidedways.2Do</string>
<string>com.appigo.todo</string>
<string>pocketinformant</string>
<string>com.innov8tion.iTask</string>
<string>iMExchange</string>
<string>com.apple.reminders</string>
<string>com.6wunderkinder.wunderlistmobile</string>
<string>com.basil.Finish-</string>
<string>com.principal.prune</string>
</array>
<array>
<string>com.culturedcode.ThingsTouch</string>
<string>com.olefsky.toodledo</string>
<string>com.binaryhammer.3030</string>
<string>com.beHappy.Productive</string>
</array>
</array>
<key>displayName</key>
<string>Productivity</string>
<key>listType</key>
<string>folder</string>
</dict>
</array>
<key>iconLists</key>
<pages orig="array">
<!-- array replaced by & represents ALL <pages> -->
<page num="1" orig="array">
<!-- array replaced by & represents ONE <page> -->
<string>com.apple.mobilephone</string>
<string>com.apple.mobilecal</string>
<string>com.apple.mobileslideshow</string>
<string>com.apple.camera</string>
<string>com.apple.videos</string>
<string>com.apple.youtube</string>
<string>com.apple.Maps</string>
<string>com.apple.weather</string>
<string>com.apple.mobilenotes</string>
<string>com.apple.reminders</string>
<string>com.apple.mobiletimer</string>
<string>com.apple.gamecenter</string>
<dict>
<!-- Inner <dict> represents Folders -->
<key>displayName</key>
<string>Apple</string>
<key>iconLists</key>
<array>
<array>
<string>com.apple.mobileme.fmf1</string>
<string>com.apple.Cards</string>
<string>com.apple.iBooks</string>
</array>
</array>
<key>listType</key>
<string>folder</string>
</dict>
<string>com.apple.MobileStore</string>
<string>com.apple.AppStore</string>
<string>com.apple.Preferences</string>
</page>
<page>
<dict>
<key>displayName</key>
<string>Utilities</string>
<key>iconLists</key>
<array>
<array>
<string>com.apple.MobileAddressBook</string>
<string>com.apple.calculator</string>
<string>com.apple.VoiceMemos</string>
</array>
</array>
<key>listType</key>
<string>folder</string>
</dict>
<dict>
<key>displayName</key>
<string>Jailbreak</string>
<key>iconLists</key>
<array>
<array>
<string>com.saurik.Cydia</string>
<string>libactivator</string>
<string>eu.heinelt.ifile</string>
<string>crash-reporter</string>
<string>com.googlecode.mobileterminal.Terminal</string>
</array>
</array>
<key>listType</key>
<string>folder</string>
</dict>
.....
Too long - Also uploaded to dropbox share folder..
.....
</page>
</pages>
</all>
</plist>

Current Thread