Monday, April 12, 2010

Lookup Fields and XSL

Ahh, XSL...Cause of and solution to all of SharePoint's formatting woes.

I'm displaying a document library in an XSLT data view on my SharePoint page, and one of the fields I want to show is a lookup type.

Now, lookup type field values are stored with both the string value and the ID, like so:

17;#Value


...Which is fine, right up until you try to include that field in your data view, and get pages of 17#;Value, 18#;AnotherValue, etc.

Thankfully, XSL provides its own solution. Use the substring-after command to strip out those pesky IDs....Or, conversely, use substring-before if you just want the IDs!


Code sample:


<xsl:value-of select="substring-after(@Fieldname, ';#')" />

Wednesday, April 7, 2010

Sharepoint Navigation: It Hurts So Good

Just when you think you've mastered navigation in SharePoint, something new gets tossed at you.

My own ego was deflated when a client requested a 3rd-level flyout on our top navigation, something like this:


HOME SUBSITEA SUBSITEB SUBSITEC
Nav 1
Nav 2
Heading->
Subnav 1
Subnav 2
Subnav 3


Sure, I confidently asserted, I can definitely do that! No sweat.

Smugly, I set up a heading and a bunch of links beneath that on SubsiteA. Still brimming with confidence, I clicked 'OK', and moused over the navigation bar to admire my work.

But...it wasn't there. Just...nothing. Did I save it properly? I doublechecked, and yes, I saw the heading and all the subnav items still there in the admin page. Mocking me. I could almost hear their laughter.

I mucked around with different combinations of relative and absolute URLs, and replicated the issue on other sub-sites. Sure enough, headings just refused to show up on anything except the root site.

Annoyed, I turned to the web for help, and finally dug up a post by Millerw that addressed the problem. Millerw suggested changing the data source for the navigation to "CurrentNavSiteMapProvider". I checked, and found that my source was "CombinedNavSiteMapProvider". Well, OK - worth a try!

I swapped sources, and checked out my site. Um...Not quite what I was looking for. Yes, I could now see the flyout on that subsite, but navigation to all other subsites was messed up. Everything was oriented vertically, I wasn't seeing all the subsites I wanted to, etc., etc.

Beginning to despair, I searched around and ended up on the Microsoft Enterprise Content Management Team blog (there's a mouthful), where they have a VERY good deep-dive on MOSS navigation. They actually had a lot of useful information on CombinedNavSiteMapProvider...And in their sample code, they had the following line:

TrimNonCurrentTypes="Heading"

AH-HAH, they're turning off 'heading' in the navigation - that MUST mean that CombinedNavSiteMapProvider can show headings!

Sure enough, by tweaking settings I was able to get the code below to work. Now I see all my horizontal top nav items just as before, with the addition of headers on my sub-sites.

I'll tell ya, if SharePoint is good for anything, it's good for keeping your ego in check.

The code:



<publishingnavigation><?xml:namespace prefix = publishingnavigation /><publishingnavigation:portalsitemapdatasource id="GlobalNavDataSource" treatstartingnodeascurrent="true" startingnodeoffset="0" startfromcurrentnode="true" showstartingnode="false" sitemapprovider="CombinedNavSiteMapProvider" runat="server"></publishingnavigation:portalsitemapdatasource>