You can simply write XPath expressions and match patterns with the condition you have have e.g. Tbl2[a2 = 'APPLE'], here is a sample stylesheet
< xml version="1.0" encoding="UTF-8" > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="DataSet"> <Body> <xsl:apply-templates select="Tbl1"/> <Tropical> <xsl:apply-templates select="Tbl2[a2 = 'APPLE']"/> </Tropical> <Organic> <xsl:apply-templates select="Tbl2[a2 = 'PEACH']"/> </Organic> </Body> </xsl:template>
<xsl:template match="Tbl1"> <Retail> <xsl:apply-templates/> </Retail> </xsl:template>
<xsl:template match="A"> <book> <xsl:apply-templates/> </book> </xsl:template>
<xsl:template match="B"> <Pen> <xsl:apply-templates/> </Pen> </xsl:template>
<xsl:template match="Tbl2[a2 = 'APPLE']"> <Grade> <xsl:apply-templates/> </Grade> </xsl:template>
<xsl:template match="Tbl2[a2 = 'PEACH']"> <Sample> <xsl:apply-templates/> </Sample> </xsl:template>
<xsl:template match="a1"> <No> <xsl:apply-templates/> </No> </xsl:template>
<xsl:template match="a2"> <Fruit> <xsl:apply-templates/> </Fruit> </xsl:template>
<xsl:template match="a3"> <Qty> <xsl:apply-templates/> </Qty> </xsl:template>
</xsl:stylesheet>
|