gpt4 book ai didi

asp.net - DDR TreeView 菜单显示选定的根及其子节点

转载 作者:数据小太阳 更新时间:2023-10-29 01:52:07 26 4
gpt4 key购买 nike

我正在为 DotNetNuke 开发 DDR Treeview 菜单,以仅显示选定的根项目及其要展开的子节点。这就是我想要实现的目标。(左侧垂直菜单)有什么建议吗?

enter image description here

这是 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"/>
<xsl:param name="ControlID" />
<xsl:param name="Options" />
<xsl:template match="/*">
<xsl:apply-templates select="root" />
</xsl:template>
<xsl:template match="root">
<xsl:if test="node">
<ul class="treeview filetree" id="{$ControlID}">
<xsl:apply-templates select="node" />
</ul>
<script type="text/javascript">
jQuery(function($) {
$("#<xsl:value-of select="$ControlID" />").treeview(
<xsl:value-of select="$Options" disable-output-escaping="yes" />
);
});
</script>
</xsl:if>
</xsl:template>
<xsl:template match="node">
<li>
<xsl:if test="node and (@depth != 0 or @breadcrumb = 1)">
<xsl:attribute name="class">open</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="@enabled = 0">
<xsl:value-of select="@text" />
</xsl:when>
<xsl:otherwise>
<a href="{@url}">
<xsl:choose>
<xsl:when test="@selected=1">
<xsl:attribute name="class">selected breadcrumb</xsl:attribute>
</xsl:when>
<xsl:when test="@breadcrumb=1">
<xsl:attribute name="class">breadcrumb</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:value-of select="@text" />
</a>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="node">
<ul style="list-item-style:none">
<xsl:apply-templates select="node" />
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>

最佳答案

如果您提供了您想要转换的输入代码的示例,将会有所帮助。

我假设它基本上是这样的:

<root>
<node enabled="1" depth="1" text="Service" selected="true" breadcrumb="0"/>
<node>
<node>
<node/>
</node>
</node>
<node>
<node/>
</node>
<node/>
</root>

您可以跳过第一个模板匹配和第一个 if 元素,直接只匹配您感兴趣的内容。无需测试,像这样的事情应该可以解决问题:

<!-- ... -->
<!-- process only "root" elements that have at least one "node" element -->
<xsl:template match="/root[node]">
<ul class="treeview filetree" id="{$ControlID}">
<xsl:apply-templates select="node" />
</ul>
<!-- ... -->
</xsl:template>
<xsl:template match="node">
<!-- ... -->
</xsl:template>

关于asp.net - DDR TreeView 菜单显示选定的根及其子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14959022/

26 4 0