How to group with XSLT

Bonjour,

Note: I used Altova 2008 XML Spy which is a great tool.

I just spent a little while trying to understand grouping of data using XSLT.

I first started out using XSLT 2.0 and was quite happy with how easy it was to group until I tried to transform the XSLT with C#. Guess what, .NET 2.0 doesnt support XSLT 2.0 even though W3C says it’s the current standard.

Anyway, so I went back to using XSLT 1.0 which was not my friend until now. It’s a lot more complex to group using XSLT 1.0 but I eventually got there.

Here is my XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

.
**



Count:

  1. :
  2. <!–
    This nested for-each loops through the City elements that have
    the same value for the State attribute as the current City in
    the outer for-each loop.
    –>

and here is my XML:

RAND
Capital
2222

LAND7
Capital
000005

LAND3
Furniture
9875

ACPB
Revenue
1111

LAND2
Furniture
3333

LAND1
Furniture
7677

YELK
Other
000005

LAND3
Furniture
9875

and here is the result:

1.Furniture
Count: 4

  1. LAND3:9875
  2. LAND2:3333
  3. LAND1:7677
  4. LAND3:9875

2.Capital
Count: 2

  1. RAND:2222
  2. LAND7:000005

3.Revenue
Count: 1

  1. ACPB:1111

4.Other
Count: 1

  1. YELK:000005
Advertisements

Workflow Send activity + WCF [DataMember] and the story of why I am an idiot!!!

If you have a class BusinessCaseContentType whose properties are not decorated with the [DataMember] attribute and you try and use a Workflow SendActivity to receive this class BusinessCaseContentType it will always come back un-populated.

using System;
using System.Runtime.Serialization;
using System.Collections.Generic;

namespace Acres.DataContracts
{
  [Serializable()]
  [DataContract]
  public class BusinessCaseContentType
  {

  private string _BusinessCaseType;

   [DataMember] // – not my friend at the moment
  public string BusinessCaseType
  {
    get { return _BusinessCaseType; }
    set { _BusinessCaseType = value; }
  }

}
}

Thing is, you wont get an error you will just get a NULL instance of BusinessCaseContentType.

Now this really sucks as I spent 2 days looking a for a needle in a haystack when in fact I was looking for a tractor in a haystack!!

Oh well, at least I know for next time!!

Can I have a beer please!!

RuSs

Making sharepoint RSS feed work behind your firewall

Morning,

Just found a great little post here that shows you how to make RSS feeds work in Sharepoint inside your company firewall.

You add the following inside the section in the site web.config.


<proxy autoDetect="true"
usesystemdefault=”false”
proxyaddress=”http://YOUR_PROXY_SERVER:YOUR_PORT_NUMBER&#8221;
bypassonlocal=”true” />

Works perfectly.. just wait a few more seconds for your site to recompile.

thanks
RuSs

Starting out with Sharepoint 2007 BDC

This post is a simple step by step of how to set up BDC.

Here is a great video that walks you though it.
Here also is a virtual lab but you will need an MSDN login for this and it needs to run in IE.
Here is the PDF that goes with the lab.

Firstly go and get:
BDC Meta Man – this will save you hours as it creates the XML defintion files for you.
http://www.lightningtools.com/bdc-meta-man/default.aspx
This tool is great although unless you pay for it you will only be able to add 2 tables max and you get a lot of popup messages telling you about the paid for version. But the free version is really good besides that.

Then you just select the type of connection you want. This post will only cover database connections.

So connect to your SQL 2005 database using the connect to datasource drop down inside BDC Meta Man.
then drag the table(s) on to the design surface. Drag 2 tables that are relates as you get more functionality in Sharepoint if you do this. (ie.. master details stuff)
Go and choose the columns you want etc… but you are better to get most of the columns as you can filter them later in MOSS.
One thing I had trouble with is not being able to connect to my database as the credentials it was passing were the IIS settings.

So in my XML defintion file that was created by BDC Meta Man I did the folllowing:

PassThrough
SqlServer
MY_SERVER_NAME
MY_DATABASE_NAME
False
MY_PASSWORD
false
MY_USER_NAME

As you can see I have put a user name and password in the config.

Ok so now you have your definition file.
Go to central adminitration and select your shared service from share services admin.
Look in the Business Data Catalog section on the right and select “Import application defintion”.
Browse to your XML def. and upload it. I left all the setting the same.

Now go to your site and enable:
Office SharePoint Server Enterprise Site Collection features
Stay in your site and edit a page you want to add these things to.
Click on Add a web part.

Choose Business Data List
AND
Business Data Related List

These 2 will be part of our master detail functionality.
The web part will prompt you to open the tool panel so do this for the business data list first.
Type: click on the book and select the parent table you configure in BDC Meta Man
Apprearance: you can change the title and widths etc..
Click ok.

Do the same for the child table.
Then click ok.

Go to the child webpart and click Edit drop down in top right corner and select connections / Get Related Item From .. and choose your parent web part.
You can also edit the view to remove some columns and do filtering if you like.
Think that’s it… spend a bit of time configuring the page as it takes a while to get it looking good.
The most important thing was the SQL username and Password I mentioned above.

RuSs

How to Serialize and Deserialize objects. Greate for WCF

This code rocks thanks to Raymond Skelly for stealing it from someone to give to me!

public static string SerialiseObject(object o)
{
StringWriter sw = new StringWriter();
try
{
XmlSerializer s = new XmlSerializer(o.GetType());
s.Serialize(sw, o);
}
catch (Exception e)
{
string x = e.Message;
}
return sw.ToString();
}

public static object DeserialiseObject(string ObjectString, Type ObjectType)
{
XmlSerializer s = new XmlSerializer(ObjectType);
return s.Deserialize(new StringReader(ObjectString));
}