xslt efficient way to check conditions

subhum4n

New Member
i just wanted to check if any way to avoid verbose coding like below in xslt1.0, where we have multiple check conditions, the output elements to be copied based on certain conditions. If the condition is not true, then the element itself will be absent in the output. The reason I am asking, we have a lot of elements present in the xsl file.My xslt\[code\]<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output omit-xml-declaration="yes" indent="yes" /> <xsl:strip-space elements="*" /> <xsl:template match="/"> <Root> <xsl:if test="Root/a/text() = '1'"> <first>present</first> </xsl:if> <xsl:if test="Root/b/text() = '1'"> <second>present</second> </xsl:if> <xsl:if test="Root/c/text() = '1'"> <third>present</third> </xsl:if> <xsl:if test="Root/d/text() = '1'"> <fourth>present</fourth> </xsl:if> </Root> </xsl:template></xsl:stylesheet>\[/code\]my input xml\[code\]<Root> <a>1</a> <b>1</b> <c>0</c> <d>1</d> </Root>\[/code\]my output\[code\]<Root> <first>present</first> <second>present</second> <fourth>present</fourth></Root>\[/code\]
 
Back
Top