Wednesday, May 23, 2007

Content Query Web Part xsl for showing the xml

I keep forgetting this, and I think I had to figure it out from scratch at least 4 times allready, so I may as well blog it.
The thing is - last time I figured it out I wanted to blog about it, and then saw that someone beat me to it - Heather Solomon already wrote about it in her blog, and I seem to remember someone else wrote a similar script.
The thing that throws me off every time is realizing that the XML that the content query web part builds for each item has the values in the attributes. So what you need to do is write xslt code to display the attributes.

Heather's article says exactly how to modify the files, so if you need that kind of help, go there now. Below is the code that I am using (slightly modified):

<xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle">
    <xsl:for-each select="@*">
        Name: <xsl:value-of select="name()" /> Value:<xsl:value-of select="." />

I have just managed to do something really cool with the web part, but I have to refine it a bit before I publish it. I promise this will knock your socks off!

No comments: