0
我試圖實現XSLT 1.0遞歸(樹)從列表看起來像這樣的XML開始:遞歸XSLT 1.0基於節點值
<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>
這必須使用XSLT 1.0,因爲我們SharePoint目前不支持2.0。
它在Windows資源管理器中應該看起來像一棵樹。
電流XSLT代碼我是:
<?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>
其示出了像結果:
其中例如 'Formulier \知情同意(IC)' 示出的所有文件夾然後將其分開,並將「Formulier」作爲「知情同意書(IC)」的母公司。 (我substringed的「根\」的位置,但是它應該顯示在上面作爲根節點)
結果舉例代碼:
<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>
誰能給我的信息或代碼源一起玩用XSLT 1.0實現這樣的事情?
在此先感謝。
Nils
請將預期結果**顯示爲代碼**。 –
我的不好,我添加了這個例子! – AppSum
這與這個問題幾乎相同:http:// stackoverflow。com/questions/872067/Creating-a-nested-tree-structure-from-a-path-in-xslt – Tomalak