Skip to content

Instantly share code, notes, and snippets.

@Sitwon
Created September 16, 2010 13:36
Show Gist options
  • Save Sitwon/582433 to your computer and use it in GitHub Desktop.
Save Sitwon/582433 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<document>
<item a="0" b="0" c="0" name="0"/>
<item a="1" b="0" c="0" name="1"/>
<item a="0" b="1" c="0" name="2"/>
<item a="1" b="1" c="0" name="3"/>
<item a="0" b="0" c="1" name="4"/>
<item a="1" b="0" c="1" name="5"/>
<item a="0" b="1" c="1" name="6"/>
<item a="1" b="1" c="1" name="7"/>
</document>
<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="paramA" select="'1'"/>
<xsl:param name="paramB" select="'1'"/>
<xsl:param name="paramC" select="'1'"/>
<xsl:template match="/document">
<xsl:text>
</xsl:text>
<xsl:variable name="items" select="item"/>
<xsl:variable name="items1">
<xsl:choose>
<xsl:when test="$paramA='1'">
<xsl:copy-of select="$items[@a='1']"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$items"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="items2">
<xsl:choose>
<xsl:when test="$paramB='1'">
<xsl:copy-of select="$items1/item[@b='1']"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$items1/item"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="items3">
<xsl:choose>
<xsl:when test="$paramC='1'">
<xsl:copy-of select="$items2/item[@c='1']"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$items2/item"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:apply-templates select="$items3"/>
</xsl:template>
<xsl:template match="document">
<xsl:text>in document</xsl:text>
</xsl:template>
<xsl:template match="item">
<result><xsl:value-of select="@name"/></result>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:transform>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment