I'm trying to achieve a recursive (tree) list in XSLT 1.0 starting from an XML that looks like this:
<list>
<row>
<icon>http://server/app/icon.gif</icon>
<title>Document</title>
<location>Root\Formulier</location>
</row>
<row>
<icon>http://server/app/icon.gif</icon>
<title>Handleiding1</title>
<location>Root\Handleidingen</location>
</row>
<row>
<icon>http://server/app/icon.gif</icon>
<title>Form</title>
<location>Root\Formulier\Informed consent (IC)</location>
</row>
<row>
<icon>http://server/app/icon.gif</icon>
<title>Handleiding2</title>
<location>Root\Handleidingen</location>
</row>
</list>
This has to use XSLT 1.0, because our SharePoint does not support 2.0 yet.
It should look like a tree in Windows Explorer.
The current XSLT code I have is:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes" />
<xsl:key name="groups" match="/list/row" use="location" />
<xsl:template match="/list">
<div class="idocument-list">
<xsl:apply-templates select="row[generate-id() = generate-id(key('groups', location)[1])]"/>
</div>
</xsl:template>
<xsl:template match="row">
<div style="margin-bottom:5px;">
<ul>
<li>
<img border="0" style="align:left;" src="/_layouts/15/images/folder.gif?rev=23" alt="map" />
<span class="ms-textLarge idocumentlist-title">
<xsl:value-of select="substring-after(location,'Root\')"/>
</span>
<ul style="display:none;">
<xsl:for-each select="key('groups', location)">
<li>
<img border="0" style="align:left;">
<xsl:attribute name="src">
<xsl:value-of select="icon"/>
</xsl:attribute>
</img>
<span>
<a>
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</span>
</li>
</xsl:for-each>
</ul>
</li>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
which shows the result like:
Where for example 'Formulier\Informed consent (IC)' shows all the folders after each other, while it should be split on the \ and show 'Formulier' as the parent of 'Informed consent (IC)'. (I substringed the 'Root\' location out, but it should show on top as root node)
Example result code:
<div class="idocument-list">
<ul>
<li>
<img style="align: left;" alt="map" src="..." border="0">
<span class="ms-textLarge idocumentlist-title">Root</span>
<ul>
<li>
<img style="align: left;" alt="map" src="..." border="0">
<span class="ms-textLarge idocumentlist-title">Formulier</span>
<ul>
<li>
<img style="align: left;" alt="map" src="..." border="0">
<span class="ms-textLarge idocumentlist-title">Informed consent (IC)</span>
<ul>
<li>
<img style="align: left;" src="..." border="0">
<span>
<a href="...">Form</a>
</span>
</li>
</ul>
</li>
<li>
<img style="align: left;" alt="map" src="..." border="0">
<span>
<a href="...">Document</a>
</span>
</li>
</ul>
</li>
<li>
<img style="align: left;" alt="map" src="..." border="0">
<span class="ms-textLarge idocumentlist-title">Handleidingen</span>
<ul>
<li>
<img style="align: left;" src="..." border="0">
<span>
<a href="...">Handleiding1</a>
</span>
</li>
<li>
<img style="align: left;" src="..." border="0">
<span>
<a href="...">Handleiding2</a>
</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Can anyone give me a source of information or code to play with to achieve something like this with just XSLT 1.0?
Thanks in advance.
Nils