xslt parsing error for left nav on all pages after first node
New to umbraco and xslt. Built a simple site with both Home (and Home.master template) and ContentPage (and ContentPage.master template) document types based off of Page (and Site.master template) document type. All non-home page nodes are of ContentPage document type. Using a simple left nav based in xslt, the home page and the first node, the About page, the left nav looks fine.
For all other nodes in the left nav, when I go to those pages, the left nav shows an xslt parse error with the output from appending ?umbDebugShowTrace=true to the url showing this 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."
I read that sometimes using preserve can have this effect, but that's not in my code. Can anyone tell me what's wrong? Here is the xslt code:
That error is happening because of the class="active" you're trying to set - if it's not executed ini the very first iteration of the loop, then you've already added text and/or child elements to the <p id="leftNav"> tag, and then you can't attach an attribute to it any longer — You'll need to do that before entering the for-each.
Which one are you really trying to set the class on?
I see! I'm very new to xslt so I was just adapting the out-of-the-box LeftNav.xslt without digging into what was happening in each piece. So, what I want is for that class="active" to be set for the current node I'm in. It seems that it's setting it only for the first, so if I'm not in the first node, it fails. Is that a correct interpretation? If that's the case, though, then why does this test fail:
Okay, climbing the learning curve. I see now that the <xsl:attribute> element refers to whatever element it sits underneath, adding the class="active" to that element's opening tag. The reason my script was breaking was because it was trying to set the <p> tag to active for each node, but the <p> element encloses the entire nav list and so had already been set to active on the first pass. I moved that attribute test to sit underneath the <a> tag, which is the element I want to be active, and now it works like a champ.
xslt parsing error for left nav on all pages after first node
New to umbraco and xslt. Built a simple site with both Home (and Home.master template) and ContentPage (and ContentPage.master template) document types based off of Page (and Site.master template) document type. All non-home page nodes are of ContentPage document type. Using a simple left nav based in xslt, the home page and the first node, the About page, the left nav looks fine.
For all other nodes in the left nav, when I go to those pages, the left nav shows an xslt parse error with the output from appending ?umbDebugShowTrace=true to the url showing this 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."
I read that sometimes using preserve can have this effect, but that's not in my code. Can anyone tell me what's wrong? Here is the xslt code:
Hi Neil,
That error is happening because of the class="active" you're trying to set - if it's not executed ini the very first iteration of the loop, then you've already added text and/or child elements to the <p id="leftNav"> tag, and then you can't attach an attribute to it any longer — You'll need to do that before entering the for-each.
Which one are you really trying to set the class on?
/Chriztian
Hi Chriztian,
I see! I'm very new to xslt so I was just adapting the out-of-the-box LeftNav.xslt without digging into what was happening in each piece. So, what I want is for that class="active" to be set for the current node I'm in. It seems that it's setting it only for the first, so if I'm not in the first node, it fails. Is that a correct interpretation? If that's the case, though, then why does this test fail:
<xsl:if test="$currentPage/ancestor-or-self::* [@level]/@id = current()/@id">
?
At first glance, it looks to be the right test, doesn't it?
Neil
Also, forgot to say that yes, removing that element entirely did get rid of the error, but I still want to add the class=active to the current node...
Okay, climbing the learning curve. I see now that the <xsl:attribute> element refers to whatever element it sits underneath, adding the class="active" to that element's opening tag. The reason my script was breaking was because it was trying to set the <p> tag to active for each node, but the <p> element encloses the entire nav list and so had already been set to active on the first pass. I moved that attribute test to sit underneath the <a> tag, which is the element I want to be active, and now it works like a champ.
Here's the change:
is working on a reply...