Forum Moderators: open

Message Too Old, No Replies

choosing a node, and conditional display

"you are here" in a nav tree

         

httpwebwitch

2:27 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



my nav tree XML looks like this:

<page id="contents.html" value="Contents">
<page id="category.html" value="Category">
<page id="subject1.html" value="Subject 1">
<page id="topic4.html" value="Topic 4"/>
<page id="topic5.html" value="Topic 5"/>
</page>
<page id="subject2.html" value="Subject 2">
<page id="topic6.html" value="Topic 6"/>
</page>
</page>
</page>

I have an XSLT that turns my XML navigation tree into tree-view navigation for a large document-based site. it uses a recursive template for all "page" elements, so if the current node has children, it keeps drilling.

<xsl:when test="count(page) > 0">

What I want to do is selectively display a node's children depending if it is an ancestor a given page - the user's "current page". So, say Mr. User is on "about.html", I would like to show the tree open to the "about.html" node by not displaying any of the cousin or nephew nodes.

is there a "xsl:when test" that can figure out if a current node is an ancestor of a particular node with a given ID?

Another thought is that I should be removing those nodes from the XML using XPathNavigator or some other .NET tool. That way the XML does the selection, and XSL only does the rendering.

I need an XML expert to hold my hand for a few minutes. anyone?

sticky me if you've tried this before

httpwebwitch

5:04 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Progress: I have given up on making an XSLT intelligent enough to open ancestry nodes. Fahget-it. My XSLT makes a pretty tree on my screen, and that's complicagted enough already.

I would rather manipulate the XML object once loaded and discard/ignore unneeded nodes.

I had a good thing going by reading my source XML document (from file), and using that to build a new XML document. then I can do my XSL transformation on that new XML document.


XmlDocument sitemap = new XmlDocument();

Then I ran into a snag: to add new child nodes, I have to getElementById. GetElementById only works when there is a DTD defining an ID attribute. well I haven't found a way to create a DTD for my virtual document.

So far this has been a wickedly difficult plunge into XML programming in .NET - up until now I had used XML extensively in Flash and PHP without nearly this much difficulty.

Are there any XML.NET gurus around here?

johnl

11:58 am on May 25, 2005 (gmt 0)

10+ Year Member



hi,


is there a "xsl:when test" that can figure out if a current node is an ancestor of a particular node with a given ID?


<xsl:choose>
<xsl:when test="ancestor::particularnode/@id='xy'"/>
</xsl:choose>

should do the job.