Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Last active August 29, 2015 14:06
Show Gist options
  • Save andrewminton/95c0f39117b4012f6297 to your computer and use it in GitHub Desktop.
Save andrewminton/95c0f39117b4012f6297 to your computer and use it in GitHub Desktop.
<data>
<hello>paste your xml here</hello>
<entry><title message="error"></title></entry>
<entry><title message="error"></title></entry>
<entry><title message="error"></title></entry>
<entry><title message="error"></title></entry>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<hi>
<xsl:value-of select="data/hello" />
</hi>
<xsl:apply-templates select="entry" mode="errors"/>
</xsl:template>
<xsl:template match="entry" mode="errors">
<xsl:if test="title/@message = 'error'">
<xsl:call-template name="dosomething">
<xsl:with-param name="error" select="1"/>
<xsl:with-param name="count" select="position()"/>
<!-- any any other initial data needed to be passed -->
<xsl:value-of select="$count"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="dosomething">
<xsl:param name="error"/>
<xsl:param name="count"/>
<!-- and others as required -->
<xsl:choose>
<xsl:when test="$error = 1">
<!-- output the last result, or nothing -->
<xsl:value-of select="$error"/>
</xsl:when>
<xsl:otherwise>
<!-- output whatever is needed here -->
<xsl:call-template name="dosomething">
<xsl:with-param name="error" select="$error"/>
<xsl:with-param name="count" select="position()"/>
<!-- any any other modified data needed to be passed -->
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment