Mega Code Archive

 
Categories / XML Tutorial / XSLT StyleSheet
 

Variable without initialization

File: Data.xml <?xml version="1.0" encoding="utf-8"?> <data>         <animal>cat</animal>     <animal>dog</animal>   <animal>cow</animal> </data> File: Transform.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet       version="1.0"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">     <xsl:variable name="color"/>     <xsl:template match="//animal">       <xsl:choose>         <xsl:when test="boolean($color)">           <P style="color:{$color}">             <xsl:value-of select="."/>           </P>         </xsl:when>         <xsl:otherwise>           <paragraph>             <xsl:value-of select="."/>           </P>         </xsl:otherwise>       </xsl:choose>     </xsl:template> </xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>         <paragraph>cat</P>     <paragraph>dog</P>   <paragraph>cow</P>