【问题标题】:DDR Treeview Menu display selected root and its child nodeDDR Treeview Menu 显示选定的根及其子节点
【发布时间】:2013-02-19 13:43:48
【问题描述】:

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

这是 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>

【问题讨论】:

  • 您应该在问题中添加 xml。
  • 您是要隐藏子项的整个行(包括 Home、About、Service/Location 和 Contact 列)还是只隐藏最左边的列?

标签: asp.net xml xslt treeview dotnetnuke


【解决方案1】:

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

我认为它基本上是这样的:

<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>

【讨论】:

    【解决方案2】:

    如果没有源 XML,真的很难弄清楚你想在这里做什么,但我想说你得到 all 节点的主要原因是模板匹配node 元素是递归的,不会隐藏后代。如果将display:none 添加到node 模板末尾的ul 元素的style 属性中(或将list-item-style 更改为display),您可能会得到您想要的。

    【讨论】:

      【解决方案3】:

      如果您只获取根项目,则需要更改为菜单定义的NodeSelector。我相信速记值RootChildren 会给你你想要的。

      【讨论】:

      • 这就是我解决问题的方法。但是,您的回答也有帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多