Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDR Treeview Menu display selected root and its child node

I'm working on a DDR Treeview menu for DotNetNuke to display only the selected Root items and its child node to be expanded. Here is what I'm trying to achieve. (Left vertical menu) Any advice please?

enter image description here

This is the xslt code and is currently displaying all root items.

<?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>
like image 567
user1781367 Avatar asked Feb 19 '13 13:02

user1781367


2 Answers

It would help if you supplied an example of the input code you would like to transform.

I assume its basically something like this:

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

You can skip the first template-match and those first if-element and directly match only what you're interested in. Without testing, something like this should do the trick:

<!-- ... -->
<!-- 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>
like image 199
Jörn Willhöft Avatar answered Nov 12 '22 03:11

Jörn Willhöft


Without the source XML it's really hard to work out what you're trying to do here, but I'd say the main reason you're getting all nodes is the the template to match the node element is recursive and does not hide the descendants. If you add display:none to the style attribute on the ul element at the end of the node template (or change list-item-style to display), you may get what you want.

like image 38
rumplestiltzkin Avatar answered Nov 12 '22 03:11

rumplestiltzkin