Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Dahl Tollestrup 73 posts 52 karma points
    Nov 25, 2009 @ 22:28
    Anders Dahl Tollestrup
    0

    XSLT trouble with nested navigation

    Hi

    I'm having some trouble with XSLT in trying of generating af nested navigation. I receive following XSLT error just before the xsl:for-each in the RenderSubNavigation template:

    System.Xml.Xsl.XslTransformException: Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.

    XSLT code:
    .....
    <xsl:param name="currentPage"/>

    <!-- XSLT variables -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

        <!-- Building two-level UL list of navigation nodes -->
        <ul class="sf-menu-x">
            <li><a href="/" title="Forsiden">Forsiden</a></li>
            <xsl:for-each select="$currentPage/ancestor-or-self::node [@level = $level]/node [string(data [@alias='pNaviHide']) != '1']">           
                <li>
                            <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                        <xsl:attribute name="class">current</xsl:attribute>
                        </xsl:if>
                        <a href="{umbraco.library:NiceUrl(@id)}" title="Gå til {@nodeName}">
                        <xsl:value-of select="@nodeName"/>
                        </a>

                    <xsl:call-template name="RenderSubNavigation">
                                      <xsl:with-param name="parent" select="."/>
                              </xsl:call-template> 

                </li>
            </xsl:for-each>
        </ul>

    </xsl:template>

    <xsl:template name="RenderSubNavigation">
       
        <xsl:param name="parent" />
       
        <!-- Build the second-level navigation list, if the parent node contain any childs -->
        <xsl:if test="count($parent/child::node [string(data [@alias='pNaviHide']) != '1']) &gt; 0">
            <ul>

    <!-- ERROR OCCURS HERE -->

                <xsl:for-each select="$parent/child::node">
                    <li>
                        <xsl:if test="$parent/node/@id = current()/@id">
                            <xsl:attribute name="class">current</xsl:attribute>
                            </xsl:if>
                        <a href="{umbraco.library:NiceUrl($parent/node/@id)}" title="Gå til {$parent/node/@nodeName}">
                            <xsl:value-of select="$parent/node/@nodeName"/>
                            </a>
                    </li>
                </xsl:for-each>

            </ul>
        </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

     

    Thanks in advance

    /Anders

     

  • Anders Dahl Tollestrup 73 posts 52 karma points
    Nov 25, 2009 @ 22:55
    Anders Dahl Tollestrup
    0

    Problem is solved. It was some error inside the xsl:for-each loop with the xsl:attribute tag

    /Anders

  • superbDotNetDeveloper 1 post 21 karma points
    May 12, 2010 @ 11:29
    superbDotNetDeveloper
    0

    Heya Anders,

    thanks for kindly posting this XSLT, it helped me create my nested navigation.

    later,

    Muzi

  • kapil 4 posts 24 karma points
    Jun 21, 2011 @ 08:14
    kapil
    0

     

    Hi , my  xslt also give error (Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.) on bold syntax given below, please help

     <xsl:for-each select="Features/ProductName">

        <xsl:variable name="FileName">

        <xsl:value-of select="@fileName"/>

        </xsl:variable>

               <td align="center">

               <xsl:choose>                          

              <xsl:when test="@fileName!=''">

             <xsl:element name="a">                                                                       

          <xsl:attribute name="onclick">OpenCarrierOutline('<xsl:value-of select="$ServerName"/>','<xsl:value-of select="$FileName"/>');</xsl:attribute>

              <xsl:attribute name="href">#</xsl:attribute>                           

       <xsl:value-of select="."/>

       </xsl:element>

       </xsl:when>

              

       </td>

         

       </xsl:for-each>

    please help 

    Thanks 

    kapil Gupta

     

     

     

  • Thijs Kuipers 43 posts 66 karma points
    Jun 28, 2011 @ 14:22
    Thijs Kuipers
    0

    Make sure you don't have a <xsl:preserve-space elements="..." /> in your stylesheet for an "a" element.

    Furthermore, you're missing a closing </xsl:choose> right before the </td>.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies