我正在尝试用标签包装重复system-folder
元素。div
我可以有两到三个system-folder
元素都用div
.
一个system-page
元素可以是之前或之后的兄弟姐妹。
关于我需要改变什么来实现这个的任何想法?我是否需要利用前面的兄弟姐妹并进行 3 次应用模板调用?
XML
<system-index-block current-time="1370982198860" name="index-block" type="folder">
<system-page id="3499046a0a1e023a19a05c9328c6e360">
<name>calendar</name>
<title>College Catalog</title>
<display-name>Enter a display name (For Navigation)</display-name>
<path>/web/catalog/calendar</path>
</system-page>
<system-folder id="348ce18d0a1e023a19a05c93941a001d">
<name>general</name>
<display-name>General Information</display-name>
<path>/web/catalog/general</path>
<system-page id="348d29520a1e023a19a05c9362978f0d">
<name>history</name>
<title>History of the College</title>
<display-name>Enter a display name (For Navigation)</display-name>
<path>/web/catalog/general/history</path>
</system-page>
</system-folder>
<system-folder id="348ce18d0a1e023a19a05c93941a001d">
<name>general</name>
<display-name>General Information</display-name>
<path>/web/catalog/general</path>
<system-page id="348d29520a1e023a19a05c9362978f0d">
<name>history</name>
<title>History of the College</title>
<display-name>Enter a display name (For Navigation)</display-name>
<path>/web/catalog/general/history</path>
</system-page>
</system-folder>
<system-page current="true" id="341f70a80a1e023a19a05c93a172e372">
<name>index</name>
<title>College Catalog</title>
<display-name>Enter a display name (For Navigation)</display-name>
<path>/web/catalog/index</path>
</system-page>
</system-index-block>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<xsl:apply-templates select="node()" />
</xsl:template>
<xsl:template match="system-page">
<xsl:variable name="x">
<xsl:element name="a">
<xsl:if test="@current='true'">
<xsl:attribute name="class">current-nav-link</xsl:attribute>
</xsl:if>
<xsl:attribute name="href"><xsl:value-of select="path"/></xsl:attribute>
<xsl:value-of select="title" />
</xsl:element>
</xsl:variable>
<xsl:choose>
<xsl:when test="parent::system-index-block">
<div class="nav-entry-link">
<xsl:copy-of select="$x" />
</div>
</xsl:when>
<xsl:otherwise>
<li>
<xsl:copy-of select="$x" />
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="system-folder">
<h2><xsl:value-of select="display-name" /></h2>
<ul>
<xsl:for-each select="system-page">
<xsl:apply-templates select="current()" />
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
输出
<div class="nav-entry-link">
<a href="/web/catalog/calendar">College Catalog</a>
</div>
<h2>General Information</h2>
<ul>
<li>
<a href="/web/catalog/general/history">History of the College</a>
</li>
<li>
<a href="/web/catalog/general/payment">test</a>
</li>
<li>
<a href="/web/catalog/general/governance">Governance</a>
</li>
</ul>
<h2>General Information</h2>
<ul>
<li>
<a href="/web/catalog/general/history">History of the College</a>
</li>
<li>
<a href="/web/catalog/general/payment">test</a>
</li>
<li>
<a href="/web/catalog/general/governance">Governance</a>
</li>
</ul>
<div class="nav-entry-link">
<a class="current-nav-link" href="/web/catalog/index">College Catalog</a>
</div>
我想像这样包装所有h2
和ul
元素:
<div class="nav-entry-link">
<a href="/web/catalog/calendar">College Catalog</a>
</div>
<div class="accordion">
<h2>test</h2>
<ul>test</ul>
<h2>test</h2>
<ul>test</ul>
</div>
<div class="nav-entry-link">
<a href="/web/catalog/calendar">College Catalog</a>
</div>