Jump to content

Calling Web.Sitemap from XSLT


kwilliams

Recommended Posts

I can tell you the benefits of using XSLT over pure ASP.NET right now. It's future proof. What if tomorrow MS decided to deprecate support for their sitemap objects? What if you decided to use PHP at some point?Also, I don't know about you, but to me, XSLT feels a lot more readable. At least it's pure markup.As for your problem... not having the complete site map file here is probably what confuses me, so I'll work with what I have. You mean that if aboutus.xml had:

<aboutus><internal_links><link>default</link><link>arealinks</link><link>faqs</link><link>contactus</link></internal_links></aboutus>

(notice my addition)You would want to get the links in the sitemap file that correspond to those keywords (if any) by using the value and ID as a key? How about this:

<xsl:variable name="uri" select="'web.sitemap'"/><xsl:for-each select="aboutus/internal_link"><ul><xsl:for-each select="link"><xsl:varible name="cur" select="."/><li><a href="{document($uri)//siteMapNode[@id = $cur]/@url}"><xsl:value-of select="document($uri)//siteMapNode[@id = $cur]/@title" /></a>: <xsl:value-of select="document($uri)//siteMapNode[@id = $cur]/@url" /></li></xsl:for-each></ul></xsl:for-each>

By the way, as far as I've heared, xsl:key is a more efficient method for this. However, I don't have enough experience with it to show you.

Link to comment
Share on other sites

As for your problem... not having the complete site map file here is probably what confuses me, so I'll work with what I have.
I've suddenly become interested in learning more about this. heh.Here's a sample of an entire Web.sitemap file. I believe that the only elements allowed are siteMap and siteMapNode:
<?xml version="1.0" encoding="utf-8" ?><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="~/Default.aspx" title="Home" description="This is the home page."> <siteMapNode url="~/AboutUs.aspx" title="About Us" description="This is an about us page." /> <siteMapNode url="~/Contact.aspx" title="Contact Us" description="Send us some stuff." /> </siteMapNode></siteMap>
In siteMap, there can be only one siteMapNode, but there can be many siteMapNode elements within that first siteMapNode and you can nest more siteMapNodes in the children siteMapNodes.I think, for the sake of future compliance, you're probably corrrect that the best bet would be to simply write your own sitemap XML file and use XSLT to transform it into the format you need rather than rely on .NETs .sitemap file structure.
Link to comment
Share on other sites

jesh...You make a very good point concerning future compatibility with ASP.NET vs. XSLT.What I liked about the web.sitemap feature most was being able to use the navigational features, especially the breadcrumbs. I now realize that I can use the same model for a XSLT transformation of internal_links.xml.boen_robot...I gave your suggested code a try, and this was the output:

...<!-- Dynamic MainColumn -->			<div id="screenmain">				<!-- dynamic page title -->				<h1><span id="ctl00_lblPageTitle">About Us</span></h1>				<br />				<span id="ctl00_SiteMapPath1"><a href="#ctl00_SiteMapPath1_SkipLink"><img alt="Skip Navigation Links" height="0" width="0" src="/phase3/WebResource.axd?d=AvErmV8chiUAyOw6Ne1jOA2&t=632996128439938112" style="border-width:0px;" /></a><span><a href="/phase3/default.aspx">Home Page</a></span><span> > </span><span>About Us</span><a id="ctl00_SiteMapPath1_SkipLink"></a></span>				<br />				<hr class="navyblueline" />				<br />				<span id="ctl00_lblPageDesc">This page contains links to information about us.</span>				<br /><br />				<?xml version="1.0" encoding="utf-8"?><ul>  <li>	<a href=""></a>: </li></ul>			</div><!-- end screenmain -->...

...but since I'm going to use the original model with the code I already have developed for internal_links.xml, I won't need to use this filter anyway. Again, I really appreciate all of your help, as it's given me some great tools to accomplish what I need to do. I'll make sure to let you know when I have a complete solution so that you can check it out if you wish.Thanks everyone:)

Link to comment
Share on other sites

I didn't had much time when I wrote it and I realized it won't work well (if at all) for you shortly after I finished it :) . It's a good thing you don't really need it :) .

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...