Google Analytics

Thursday, May 8, 2014

Output Raw XML from New Content By Search Web Part

Following this blog post in an attempt to reuse some custom XML developed for SharePoint 2010, I ran into a problem with this technique for outputting raw XML from search in SharePoint 2013.  It seems other have had the same issue.

This is what I came up with to help.  It's not pretty or perfect, but it'll do for now and gives a "decent" picture of what's going on in the XML.

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:template match='/'>
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="ResultTable">
        <h1>ResultTable</h1>
        <xsl:call-template name="out">
            <xsl:with-param name="in" select="ResultTable" />
        </xsl:call-template>
        <xsl:apply-templates select="Rows" />
    </xsl:template>

    <xsl:template match="Rows">
        <h1>Rows</h1>
        <xsl:call-template name="out">
            <xsl:with-param name="in" select="Rows" />
        </xsl:call-template>
        <xsl:apply-templates select="Row" />
    </xsl:template>

    <xsl:template match='Row'>
        <h1>Row</h1>
        <xsl:call-template name="out">
            <xsl:with-param name="in" select="Row" />
        </xsl:call-template>
    </xsl:template>
   
    <xsl:template name="out">
        <xsl:param name="in" />

        <table style="border: 1px solid #000;">
            <xsl:for-each select="*">
                <tr>
                    <td style="border: 1px solid #000;">
                        <xsl:value-of select="name()" />
                    </td>
                    <td style="border: 1px solid #000;">
                        <xsl:value-of select="." />
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>