Skip to content

Instantly share code, notes, and snippets.

@chids
Created May 30, 2011 20:23
Show Gist options
  • Save chids/999412 to your computer and use it in GitHub Desktop.
Save chids/999412 to your computer and use it in GitHub Desktop.
Confluence Macro - Render XML response from HTTP service
#set($path=$param0.replace("::", "="))
#set($space=$renderContext.getOriginalContext().getSpaceKey())
#if($space.equals("PRIVATE"))
#set($domain="http://your.internal.url")
#else
#set($domain="http://your.public.url")
#end
#set($url="${domain}${path}")
[$url]
#set($helper=$action.getHelper())
#set($xml=$helper.renderConfluenceMacro("{xslt:source=#$url|output=wiki|style=path.to.xslt.here}{xslt}"))
#set($xml=$xml.replace("<p>", ""))
#set($xml=$xml.replace("</p>", ""))
#set($xml=$xml.replace("<br/>", ""))
#set($xml=$xml.replace("&lt;", "<"))
#set($xml=$xml.replace("&gt;", ">"))
{code:xml}
$xml
{code}
{render-xml:/some/service/endpoint?a-query-param::and-its-value}
<!-- (c) John Mongan, copied from: http://www.dpawson.co.uk/xsl/sect2/pretty.html -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:param name="indent-increment" select="' '" />
<xsl:template match="*">
<xsl:param name="indent" select="'&#xA;'"/>
<xsl:value-of select="$indent"/>
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates>
<xsl:with-param name="indent" select="concat($indent, $indent-increment)"/>
</xsl:apply-templates>
<xsl:if test="*">
<xsl:value-of select="$indent"/>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()|processing-instruction()">
<xsl:copy />
</xsl:template>
<!-- WARNING: this is dangerous. Handle with care -->
<xsl:template match="text()[normalize-space(.)='']"/>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment