Click to See Complete Forum and Search --> : xpath attribute help


csrabine
05-11-2006, 11:29 AM
Calling Xpath experts for help...

I have a sitemap file where the page nodes (siteMapNode) have an attribute "displayinmenu". (See below for abbreviated structure.) The first siteMapNode is the Home page. I want to retrieve the nodes under the Home page with the decendant structure intact, but I only want nodes that have displayinmenu=true. siteMap/siteMapNode/siteMapNode[@displayinmenu='true'] returns the nodes I want (Products and Support but not Sitemap), but the decendants of those nodes still include displayinmenu=false. How can I get the results I am looking for?


<?xml version="1.0" encoding="utf-8"?>
<siteMap>
<siteMapNode title="Home" description="Home" url="/index.aspx" displayinmenu="false" displayinmap="true">
<siteMapNode title="Products" description="Products" url="/Products/index.aspx" displayinmenu="true" displayinmap="true">
<siteMapNode title="Overview" description="Products Overview" url="/Products/index.aspx?v=2" displayinmenu="true" displayinmap="true" />
<siteMapNode title="Product One" description="Product One" url="/Products/prod1.aspx" displayinmenu="true" displayinmap="true">
<siteMapNode title="Product One Package One" description="Product One Package One" url="/Products/prod1pack1.aspx" displayinmenu="true" displayinmap="true">
<siteMapNode title="Product One Package One Detail One" description="Product One Package One Detail One" url="/Products/prod1pack1detail1.aspx" displayinmenu="false" displayinmap="false" />
<siteMapNode title="Product One Package One Detail Two" description="Product One Package One Detail Two" url="/Products/prod1pack1detail2.aspx" displayinmenu="false" displayinmap="false" />
</siteMapNode>
</siteMapNode>
<siteMapNode title="Resources" description="Resources" url="/Products/Resources/index.aspx" displayinmenu="false" displayinmap="false">
<siteMapNode title="System Requirements" description="System Requirements" url="/Products/Resources/requirements.aspx" displayinmenu="false" displayinmap="false" />
<siteMapNode title="Architecture" description="Architecture" url="/Products/Resources/architecture.aspx" displayinmenu="false" displayinmap="false" />
<siteMapNode title="Support" description="Support" url="/Support/" displayinmenu="true" displayinmap="false" />
<siteMapNode title="Technical White Papers" description="Technical White Papers" url="/Products/Resources/whitepapers.aspx" displayinmenu="false" displayinmap="false" />
</siteMapNode>
<siteMapNode title="Request Info" description="Request Info" url="/requestinfo.aspx?path=products" displayinmenu="true" displayinmap="false" />
</siteMapNode>
<siteMapNode title="Support" description="Support" url="/Support/index.aspx" displayinmenu="true" displayinmap="true" />
<siteMapNode title="Sitemap" description="Sitemap" url="/sitemap.aspx" displayinmenu="false" displayinmap="true" />
</siteMapNode>
</siteMap>


Thanks!

Stephen Philbin
05-12-2006, 11:18 AM
Well I certainly wouldn't call myself an "expert" of Xpath, but I think this might do the trick: /siteMap/descendant-or-self::siteMapNode[attribute::displayinmenu='true']

Let me know if it floats yer boat.

csrabine
05-15-2006, 01:07 PM
/siteMap/descendant-or-self::siteMapNode[attribute::displayinmenu='true']

returns all the nodes as if they were in the same level. What I want is to keep the structure intact (nodes stay in their current levels), but filter out all the displayinmenu=false nodes.

I think it may not be possible to get what I want with Xpath?

Stephen Philbin
05-16-2006, 10:08 AM
As far as I know, to keep the actual structure you'll need to do multiple Xpath expressions, rebuilding the structure tier by tier with each expression.

Are you using XSLT or the DOM here though? If you want to quickly and easily extract a chunk of the document with its structure intact, then you want to be using the DOM, not XSLT.

csrabine
05-17-2006, 09:59 AM
I am binding the xml nodes to a third-party .net control. The easiest way to do that is to use an xmldatasource control with an xpath expression that filters out the results you want. But since it appears that one xpath expression will not be sufficient to retrieve the results I want, I am binding the nodes to the control in a different way -- I retrieve the sitemapnodecollection, iterate through the nodes and build the resultset after filtering out the displayinmenu=false nodes.