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.
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
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']) > 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
Problem is solved. It was some error inside the xsl:for-each loop with the xsl:attribute tag
/Anders
Heya Anders,
thanks for kindly posting this XSLT, it helped me create my nested navigation.
later,
Muzi
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
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>.
is working on a reply...