Mega Code Archive

 
Categories / XML / XSLT StyleSheet
 

Xsl

File: Data.xml <?xml version="1.0" encoding="utf-8"?> <data>           <color>blue</color>     <color>navy</color>     <color>green</color>     <color>lime</color>     <color>red</color> </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:template match="color">       <TABLE>         <TR>           <TD>             <xsl:attribute name="style"><xsl:text>color:</xsl:text><xsl:value-of select="."/></xsl:attribute>             <xsl:value-of select="."/>           </TD>         </TR>       </TABLE>     </xsl:template> </xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>           <TABLE><TR><TD style="color:blue">blue</TD></TR></TABLE>     <TABLE><TR><TD style="color:navy">navy</TD></TR></TABLE>     <TABLE><TR><TD style="color:green">green</TD></TR></TABLE>     <TABLE><TR><TD style="color:lime">lime</TD></TR></TABLE>     <TABLE><TR><TD style="color:red">red</TD></TR></TABLE>