Umbraco/Samples and Articles/XSLT/Print Entire XML Document

It is sometimes difficult to understand where your Xslt logic has gone wrong when you can't actually get a big picture view of the Xml structure that is being sent to your XSLT file. This Xslt macro will provide a tabular printout of the entire XML tree as seen by $currentPage. This macro will output the entire Xml tree of your website so be careful when you use this. I found this macro to be of great help trying to get started with XSLT processing in Umbraco.

 <!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]> 

 

  XPath view of your document The structure of your document (as defined by          the XPath standard) is outlined below.

 

 

 

    text:  <xsl:value-of select="."/> </xsl:if> </xsl:template>

<xsl:template name="namespace-node"> </xsl:template>

<xsl:template match="*"> </xsl:when> <xsl:otherwise> <td bgcolor="#CCCC99" colspan="2"> element:  <xsl:text>&lt;</xsl:text> <xsl:value-of select="name"/> <xsl:text>&gt;</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:for-each select="namespace::*"> <td bgcolor="#CCCC99" width="15"> <td bgcolor="#CC99CC"> <xsl:call-template name="namespace-node"/> </xsl:for-each> <xsl:for-each select="*|comment|processing-instruction|text"> <tr bgcolor="#CCCC99"> <xsl:apply-templates select="."/> </xsl:for-each> </xsl:template>

</xsl:stylesheet>

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="msxml umbraco.library">

<xsl:output method="html"/> <xsl:param name="currentPage"/>

<xsl:template match="/"> <DIV style="float:bottom; margin: 15px;" > XPath view of your document The structure of your document (as defined by          the XPath standard) is outlined below.

</DIV> </xsl:template>

<xsl:template match="comment"> </xsl:template>

<xsl:template match="processing-instruction"> </xsl:template>

<xsl:template match="text"> <xsl:if test="string-length(normalize-space(.))"> <td bgcolor="#CCCC99" width="15"> <td bgcolor="#FFCC99" width="100%"> text:  <xsl:value-of select="."/> </xsl:if> </xsl:template>

<xsl:template name="namespace-node"> </xsl:template>

<xsl:template match="*"> </xsl:when> <xsl:otherwise> <td bgcolor="#CCCC99" colspan="2"> element:  <xsl:text>&lt;</xsl:text> <xsl:value-of select="name"/> <xsl:text>&gt;</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:for-each select="namespace::*"> <td bgcolor="#CCCC99" width="15"> <td bgcolor="#CC99CC"> <xsl:call-template name="namespace-node"/> </xsl:for-each> <xsl:for-each select="*|comment|processing-instruction|text"> <tr bgcolor="#CCCC99"> <xsl:apply-templates select="."/> </xsl:for-each> </xsl:template>

</xsl:stylesheet>