Quantcast
Channel: Development With A Dot
Viewing all articles
Browse latest Browse all 404

Access Navigation Nodes in SharePoint XSLT

$
0
0

SharePoint relies on ASP.NET Site Map Providers for generating navigation links on its default pages. Specifically, the default Web.config file registers a (big!) number of providers, which control different aspects of its navigation:

   1:<siteMapdefaultProvider="CurrentNavigation"enabled="true">
   2:<providers>
   3:<addname="SPNavigationProvider"type="Microsoft.SharePoint.Navigation.SPNavigationProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
   4:<addname="SPSiteMapProvider"type="Microsoft.SharePoint.Navigation.SPSiteMapProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
   5:<addname="SPContentMapProvider"type="Microsoft.SharePoint.Navigation.SPContentMapProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
   6:<addname="SPXmlContentMapProvider"siteMapFile="_app_bin/layouts.sitemap"type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
   7:<addname="AdministrationQuickLaunchProvider"description="QuickLaunch navigation provider for the central administration site"type="Microsoft.Office.Server.Web.AdministrationQuickLaunchProvider, Microsoft.Office.Server.UI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
   8:<addname="SharedServicesQuickLaunchProvider"description="QuickLaunch navigation provider for shared services administration sites"type="Microsoft.Office.Server.Web.SharedServicesQuickLaunchProvider, Microsoft.Office.Server.UI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
   9:<addname="GlobalNavSiteMapProvider"description="CMS provider for Global navigation"type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"NavigationType="Global"EncodeOutput="true"/>
  10:<addname="CombinedNavSiteMapProvider"description="CMS provider for Combined navigation"type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"NavigationType="Combined"EncodeOutput="true"/>
  11:<addname="CurrentNavSiteMapProvider"description="CMS provider for Current navigation"type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"NavigationType="Current"EncodeOutput="true"/>
  12:<addname="CurrentNavSiteMapProviderNoEncode"description="CMS provider for Current navigation, no encoding of output"type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"NavigationType="Current"EncodeOutput="false"/>
  13:<addname="GlobalNavigation"description="Provider for MOSS Global Navigation"type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"NavigationType="Combined"Version="14"/>
  14:<addname="CurrentNavigation"description="Provider for MOSS Current Navigation"type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"NavigationType="Current"Version="14"/>
  15:<addname="SiteDirectoryCategoryProvider"description="Site Directory category provider"type="Microsoft.SharePoint.Portal.WebControls.SiteDirectoryCategoryProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  16:<addname="MySitePersonalQuickLaunchProvider"description="MySite personal quick launch provider"type="Microsoft.SharePoint.Portal.MySitePersonalQuickLaunchProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  17:<addname="MySiteHostTopNavigationProvider"description="MySite host top navigation provider"type="Microsoft.SharePoint.Portal.MySiteHostTopNavigationProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  18:<addname="GlobalNavigationSwitchableProvider"description="Provider for MOSS Global Navigation, which maps to GlobalNavigation or GlobalNavigationTaxonomyProvider according to Navigation Settings"type="Microsoft.SharePoint.Publishing.Navigation.SwitchableSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"DefaultTargetProviderName="GlobalNavigation"Version="15"/>
  19:<addname="CurrentNavigationSwitchableProvider"description="Provider for MOSS Current Navigation, which maps to GlobalNavigation or CurrentNavigationTaxonomyProvider according to Navigation Settings"type="Microsoft.SharePoint.Publishing.Navigation.SwitchableSiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Version="15"DefaultTargetProviderName="CurrentNavigation"/>
  20:<addname="GlobalNavigationTaxonomyProvider"description="Provider for MOSS Global Navigation, driven by the Taxonomy feature"type="Microsoft.SharePoint.Publishing.Navigation.TaxonomySiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Version="15"/>
  21:<addname="CurrentNavigationTaxonomyProvider"description="Provider for MOSS Global Navigation, driven by the Taxonomy feature"type="Microsoft.SharePoint.Publishing.Navigation.TaxonomySiteMapProvider, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Version="15"/>
  22:<addname="MySiteMapProvider"description="MySite provider that returns areas and based on the current user context"type="Microsoft.SharePoint.Portal.MySiteMapProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  23:<addname="MySiteLeftNavProvider"description="MySite Left Nav provider that returns areas and based on the current user context"type="Microsoft.SharePoint.Portal.MySiteLeftNavProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  24:<addname="MySiteDocumentStaticProvider"description="MySite Document library provider that returns static links to lists in the site"type="Microsoft.SharePoint.Portal.MySiteDocumentStaticProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  25:<addname="MySiteSitesPageStaticProvider"description="MySite Document library provider that returns static links to lists on the Sites page"type="Microsoft.SharePoint.Portal.MySiteSitesPageStaticProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  26:<addname="MySiteSubNavProvider"description="MySite Sub Nav provider that returns areas and based on the current user context"type="Microsoft.SharePoint.Portal.MySiteSubNavProvider, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  27:<addname="EduTopNavProvider"description="Top Nav Site Map Provider for Education My Site Host"type="Microsoft.Office.Education.WebUI.EduTopNavProvider, Microsoft.Office.Education.WebUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  28:<addname="MySiteHostQuickLaunchProvider"description="Quick Launch Site Map Provider for Education My Site Host"type="Microsoft.Office.Education.WebUI.EduQuickLaunchProvider, Microsoft.Office.Education.WebUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
  29:</providers>
  30:</siteMap>

It is possible to use a Site Map Data Source (SiteMapDataSource) to feed a DataFormWebPart with navigation information, so that you can play with it using XSLT.

For example, let’s pick one of the providers, SPNavigationProvider, which is registered, appropriately, as SPNavigationProvider. This one is capable of returning the global navigation (Global Navigation) and the quick links (Current Navigation). In order to select one or the other, we supply a special key to its StartingNodeUrl property:

  • sid:1000: Home Page;
  • sid:1002: Global Navigation;
  • sid:1025: Current Navigation;
  • sid:1040: Search.

In case you are wondering, these values are defined in the public properties of the SPNavigation class.

This example will list all attributes of all the nodes:

   1:<WebPartPages:DataFormWebPartrunat="server">
   2:<DataSources>
   3:<asp:SiteMapDataSourceSiteMapProvider="SPNavigationProvider"ShowStartingNode="false"StartingNodeUrl="sid:1002"runat="server"/>
   4:</DataSources>
   5:<Xsl>
   6:<xsl:stylesheetxmlns:x="http://www.w3.org/2001/XMLSchema"xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"version="1.0"exclude-result-prefixes="xsl msxsl ddwrt"xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"xmlns:asp="http://schemas.microsoft.com/ASPNET/20"xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:msxsl="urn:schemas-microsoft-com:xslt"xmlns:SharePoint="Microsoft.SharePoint.WebControls"xmlns:ddwrt2="urn:frontpage:internal">
   7:<xsl:outputmethod="html"/>
   8:  
   9:<xsl:templatematch="/">
  10:<xsl:for-eachselect="dataRoot">
  11:<xsl:for-eachselect="NavigateUIData">
  12:<p>
  13:                             Name: <xsl:value-ofselect="@Name"/>
  14:                             Value: <xsl:value-ofselect="@Value"/>
  15:                             NavigateUrl: <xsl:value-ofselect="@NavigateUrl"/>
  16:                             Description: <xsl:value-ofselect="@Description"/>
  17:<xsl:iftest="substring(@NavigateUrl, string-length(@NavigateUrl) - string-length('.aspx') + 1) = '.aspx'">
  18:                                 (ASPX)
  19:</xsl:if>
  20:<xsl:iftest="substring(@NavigateUrl, string-length(@NavigateUrl) - string-length('/') + 1) = '/'">
  21:                                 (Subsite)
  22:</xsl:if>
  23:</p>
  24:</xsl:for-each>
  25:</xsl:for-each>
  26:</xsl:template>
  27:</xsl:stylesheet>
  28:</Xsl>
  29:</WebPartPages:DataFormWebPart>

You can see that the SiteMapDataSource returns XML in the form:

   1:<dataRoot>
   2:<NavigateUIDataName="Some Name"Value="Some Value"NavigateUrl="Some Url"Description="Some Description"/>
   3:</dataRoot>

Attributes are mostly self-explanatory, but Name and Value have the same content and Description always appears to be empty. For subsites, the NavigateUrl attribute will end in a /. Depending on the provider, it is possible to have nested NavigateUIData nodes.

If you set the ShowStartingNode property to true, you will also get a root node containing the name (for sid:1000 it is Home, for sid:1002 it is SharePoint Top Navigation Bar, for sid:1025 it is Quick Launch and for sid:1040 it is Search) and URL of the current site

Unfortunately, there isn’t much documentation (read: none) about these providers, except, of course, their methods and properties, so you have to figure out yourself. One thing that can be useful is this XSLT that will give you all the nodes and their attributes:

   1:<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:msxsl="urn:schemas-microsoft-com:xslt"exclude-result-prefixes="msxsl asp"xmlns:asp="System.Web.UI.WebControls"xmlns:ddwrt2="urn:frontpage:internal"><xsl:outputmethod="html"/>
   2:<xsl:templatematch="*">
   3:<xsl:paramname="path"select="''"/>
   4:<xsl:variablename="previous"select="count(preceding-sibling::*[name()=name(current())])"/>
   5:<xsl:variablename="countprevious"select="count(following-sibling::*[name()=name(current())])"/>
   6:<xsl:variablename="fullpath"select="concat($path, '/', name(), substring(concat('[', $previous + 1, ']'), 1 div ($countprevious or $previous)))"/>
   7:<p><xsl:value-ofselect="$fullpath"/></p>
   8:<xsl:apply-templatesselect="@*|*">
   9:<xsl:with-paramname="path"select="$fullpath"/>
  10:</xsl:apply-templates>
  11:</xsl:template>
  12:<xsl:templatematch="@*">
  13:<xsl:paramname="path"select="''"/>
  14:<xsl:value-ofselect="concat($path, '/@', name())"/>: <xsl:value-ofselect="."/>
  15:<br/>
  16:</xsl:template>
  17:</xsl:stylesheet>


Viewing all articles
Browse latest Browse all 404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>