Straight to the point:
It might make this a lot simpler for people to help me if I just say it like this:
I need to
-select all nodes in a branch of the xml file
-where one of the nodes in that branch
-contains a node with an attribute "navigateurl" that is equal to $RequestedPage
But if not please read on for my longer explanation of my problem!
I am using AspDotNetStorefront which makes use of XSLT transformations to do various things. I am having a problem with making a submenu that only shows sections of an xml file.
I have an xml menu that has <page> elements nested inside each other to form a sitemap style tree.
I have built an xslt that will recursively traverse the xml and transform this into a ul list.
The storefront also injects a separate node that contains the url of the currently requested page.
Question
--------------------------------------------
When I compare the <page> element to the current page variable I only want to show the <page> elements from that section of the tree. So if its a page halfway down the "about us" section of the tree I only want to show "about us" pages.
Please take a look at my xslt and tell me how I can pass the correct node-set to my template so that I only have one "branch" of the tree which is whichever branch the current page is in.
Example:
For this tree layout (presume that terms.aspx is the current page):
--home.aspx
--aboutus.aspx
---privacypolicy.aspx
---terms.aspx
--anotherunwantedsection.aspx
---unwantedpage.aspx
---unwantedpage2.aspx
How do I only get the about us branch?
--------------------------------------------
My XML File:
Note - the xml file is loaded into a larger set so that's why my xslt references this file as /root/MenuData/menu instead of /menu
HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<menu>
<!-- NOTE - Do not prefix urls with / -->
<page navigateurl="t-about.aspx" anchortext="About Us">
<page navigateurl="t-about-returns-policy.aspx" anchortext="Return Policy" />
<page navigateurl="t-about-privacy-policy.aspx" anchortext="Privacy Policy" />
<page navigateurl="t-about-terms-and-conditions.aspx" anchortext="Terms & Conditions" />
<page navigateurl="t-about-accessibility.aspx" anchortext="Accessibility" />
<page navigateurl="t-about-payment-and-shipping.aspx" anchortext="Payment & Shipping Options" />
<page navigateurl="t-about-doctor-information.aspx" anchortext="Doctor Information" />
</page>
<page navigateurl="c-1-eye-support-products.aspx" anchortext="Eye Support Products">
<page navigateurl="p-4-n-acetyl-carnosine.aspx" anchortext="N-Acetyl-Carnosine Eye Drops">
<page navigateurl="t-can-c-testimonials.aspx" anchortext="Testimonials" />
<page navigateurl="t-can-c-faqs.aspx" anchortext="Can-C FAQs" />
<page navigateurl="t-can-c-about.aspx" anchortext="About Can-C">
<page navigateurl="t-can-c-about-ingredients.aspx" anchortext="Can-C Ingredients & Instructions" />
<page navigateurl="t-can-c-about-how.aspx" anchortext="How and Why Can-C Reverses Cataracts" />
</page>
<page navigateurl="t-dr-babizhayev-interviews-and-more.aspx" anchortext="Dr Babizhayev Interviews & More">
<page navigateurl="t-dr-babizhayev-interview-2001.aspx" anchortext="Dr. Babizhayev interview 2001" />
<page navigateurl="t-dr-babizhayev-interview-2003.aspx" anchortext="Dr. Babizhayev Interview 2003" />
<page navigateurl="t-dr-babizhayev-warning.aspx" anchortext="Dr. Babizhayev Warning" />
<page navigateurl="t-dr-babizhayev-biography.aspx" anchortext="Dr. Babizhayev Biography" />
<page navigateurl="t-innovative-vision-products.aspx" anchortext="Innovative Vision Products - Company Overview" />
</page>
<page navigateurl="t-can-c-science-and-research.aspx" anchortext="Science & Research">
<page navigateurl="t-clinical-publications.aspx" anchortext="Clinical Publications" />
<page navigateurl="#" anchortext="Ocular Support" />
<page navigateurl="#" anchortext="How and Why Can-C Reverses Cataracts" />
<page navigateurl="t-can-c-dr-robert-mason-interview.aspx" anchortext="Dr. Robert Mason Interview" />
<page navigateurl="t-can-c-cataract-surgery-risks.aspx" anchortext="Cataract Surgery Risks - Article" />
</page>
</page>
<page navigateurl="p-6-can-c-plus.aspx" anchortext="Can-C Plus">
<page navigateurl="#" anchortext="Testimonials" />
<page navigateurl="#" anchortext="Science & Research" />
</page>
<page navigateurl="p-5-can-c-for-dogs.aspx" anchortext="Can-C For Dogs">
<page navigateurl="t-can-c-dogs-testimonials.aspx" anchortext="Testimonials" />
<page navigateurl="#" anchortext="Science & Research" />
</page>
<page navigateurl="p-7-macular-support-armd.aspx" anchortext="Macular Support (ARMD)">
<page navigateurl="#" anchortext="Testimonials" />
<page navigateurl="#" anchortext="Science & Research" />
</page>
</page>
<page navigateurl="t-eyeconditioninfo.aspx" anchortext="Eye Condition Info">
<page navigateurl="#" anchortext="Degenerative Eye Disease" />
<page navigateurl="#" anchortext="Cataracts" />
<page navigateurl="#" anchortext="Dry Eye Condition" />
<page navigateurl="#" anchortext="Macular Degeneration" />
<page navigateurl="#" anchortext="Glaucoma" />
<page navigateurl="#" anchortext="Presbyopia" />
<page navigateurl="#" anchortext="Retinal Disease" />
<page navigateurl="#" anchortext="Floaters (Vitreous Opacities)" />
<page navigateurl="#" anchortext="Corneal Disorders" />
<page navigateurl="#" anchortext="Ocular Inflamation" />
</page>
</menu>
And my XSLT File:
HTML Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
<xsl:output method="html" omit-xml-declaration="yes" />
<!-- note - path below should be relative -->
<!-- <xsl:variable name="Menu" select="document('/skins/Skin_1/subpagemenu.xml', /)/menu" /> -->
<xsl:variable name="RequestedPage" select="/root/System/RequestedPage" />
<xsl:template match="/">
<xsl:element name="ul">
<xsl:attribute name="id">LeftNav</xsl:attribute>
<!-- <xsl:apply-templates select="/root/MenuData/menu/page[@navigateurl=$RequestedPage]/ancestor::root/MenuData/menu/page" />-->
<!-- <xsl:apply-templates select="/root/MenuData/menu/page" /> -->
<xsl:apply-templates select="descendant::root/MenuData/menu/page[@navigateurl=$RequestedPage]" />
</xsl:element>
</xsl:template>
<xsl:template match="page">
<li>
<!-- current page highlight test: current page or ancestor of current page -->
<xsl:if test="@navigateurl = $RequestedPage or count(descendant::page[attribute::navigateurl=$RequestedPage]) > 0">
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<a href="/{@navigateurl}">
<xsl:value-of select="@anchortext"/>
</a>
<xsl:if test="count(descendant::page)>0"><!-- and () -->
<ul>
<xsl:apply-templates select="page" />
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>