我使用它使用一个定制的XSL-T的XML网站地图转换成HTML导航DNN Done Right菜单组件开发DotNetNuke的5皮肤。DotNetNuke的+的XPath =自定义导航菜单
使用XSL-T相比是建设一个导航菜单的其他方式生命的救星。然而,我遇到了一些更复杂的问题,因为我是XML-T和XPath的新手。
我想要实现的是:
- 忽略0级节点
- 遍历所有级别在选择的层级
- 一旦选定级别1节点1节点被发现,开始循环层次结构/面包屑结构直到活动级别。 在活动节点级别,循环通过
- 一旦并表明水平
- 然后玩完通过电平1节点
下面循环的所有兄弟姐妹是一个网站地图的菜单部件的示例XML块使用。
<Root>
<root>
<node id="37" text="Home" url="http://www.dnndoneright.com/Home.T37.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="0" >
<description >Upgrade your standard DNN menu - automatically and for free - to an SEO-optimised, accessible, mobile-friendly, cross-browser menu.</description>
</node>
<node id="56" text="DNN Menu" url="http://www.dnndoneright.com/DNN-Menu.T56.aspx" enabled="1" selected="0" breadcrumb="1" first="0" last="0" only="0" depth="0" >
<node id="97" text="Menu features" url="http://www.dnndoneright.com/Menu-features.T97.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="1" />
<node id="111" text="Pre-built templates" url="http://www.dnndoneright.com/Pre-built-templates.T111.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="1" >
<node id="94" text="Standard DNN menu, upgraded" url="http://www.dnndoneright.com/Standard-DNN-menu-upgraded.T94.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
<node id="124" text="Superfish template" url="http://www.dnndoneright.com/Superfish-template.T124.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="106" text="Treeview template" url="http://www.dnndoneright.com/Treeview-template.T106.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="107" text="Accordion template" url="http://www.dnndoneright.com/Accordion-template.T107.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="112" text="Dropdown template" url="http://www.dnndoneright.com/Dropdown-template.T112.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="96" text="Mega-menu" url="http://www.dnndoneright.com/Mega-menu.T96.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
</node>
<node id="113" text="Getting started" url="http://www.dnndoneright.com/Getting-started.T113.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="1" >
<node id="114" text="Installing the menu" url="http://www.dnndoneright.com/Installing-the-menu.T114.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
<node id="115" text="Upgrading a SolPart menu" url="http://www.dnndoneright.com/Upgrading-a-SolPart-menu.T115.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="116" text="Upgrading a DNNMenu" url="http://www.dnndoneright.com/Upgrading-a-DNNMenu.T116.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="117" text="Installing a template" url="http://www.dnndoneright.com/Installing-a-template.T117.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="118" text="Adding to a skin" url="http://www.dnndoneright.com/Adding-to-a-skin.T118.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
</node>
<node id="119" text="Customising templates" url="http://www.dnndoneright.com/Customising-templates.T119.aspx" enabled="0" selected="0" breadcrumb="1" first="0" last="1" only="0" depth="1" >
<node id="120" text="Standard options" url="http://www.dnndoneright.com/Standard-options.T120.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
<node id="121" text="Specifying filenames" url="http://www.dnndoneright.com/Specifying-filenames.T121.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="122" text="XML format" url="http://www.dnndoneright.com/XML-format.T122.aspx" enabled="1" selected="1" breadcrumb="1" first="0" last="0" only="0" depth="2" />
<node id="123" text="Creating custom templates" url="http://www.dnndoneright.com/Creating-custom-templates.T123.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
</node>
</node>
<node id="87" text="Download" url="http://www.dnndoneright.com/Download.T87.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="0" />
<node id="85" text="Contact" url="http://www.dnndoneright.com/Contact.T85.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="0" >
<node id="129" text="Blog" url="http://www.dnndoneright.com/Blog.T129.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="1" />
<node id="130" text="Forum" url="http://www.dnndoneright.com/Forum.T130.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="1" />
</node>
</root>
</Root>
另外这里是我的(不正确)的起点,只是为了暴露我缺乏XSL/XPath的知识。 (我的代码是错误的,因为它会列出所有L1节点,而不是选择的层级只是L1节点)以下假定只能有输入一个选择的节点
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<div class="SideMenu">
<!-- Loop through all L1 nodes -->
<xsl:for-each select="Root/root/node/node">
<xsl:if test="@enabled='1'" >
<!-- Only use L1 in the current hierarchy -->
<div>
[ <xsl:value-of select="@text"/>: <xsl:value-of select="@depth"/> ]
</div>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
提示:请不要使用XML代码样本一起发布XML声明。声明(ISO-8859-1)中的编码和实际编码(UTF-8,与网页的其余部分一样)不同。 – Tomalak 2009-12-21 13:04:45
XML声明除去 – 2009-12-21 13:15:43