Applying Style Procedurally |
The other model for applying style is to select each action procedurally. A series of templates is created, such that each template explicitly selects and processes the necessary elements. |
• <xsl:for-each> <xsl:for-each select=”row”> <tr><xsl:apply-templates/></tr> </xsl:for-each> |
• Named Templates |
• <xsl:param> <xsl:param name=”type”>warning</xsl:param> |
• <xsl:call-template> <xsl:call-template name=”admonition”/> |
• <xsl:with-param> <xsl:call-template name=”admonition”> <xsl:with-param name=”type”>caution</xsl:with-param> </xsl:call-template> |
For-each Example |
foreach.xml |
<?xml version=’1.0′?> <?xml-stylesheet type=”text/xsl” href=”proc_style.xsl”?> <table> <row><entry>a1</entry><entry>a2</entry></row> <row><entry>b1</entry><entry>b2</entry></row> <row><entry>c1</entry><entry>c2</entry></row> </table> |
foreach.xsl |
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE xsl:stylesheet[ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="iso-8859-1" /> <xsl:variable name="tbl"> <tr> <td><b>Name</b></td> <td><b>Address</b></td> <td><b>Designation</b></td> </tr> </xsl:variable> <xsl:attribute-set name="tblAttrib"> <xsl:attribute name="border"> 2 </xsl:attribute> <xsl:attribute name="cellspacing"> 3 </xsl:attribute> <xsl:attribute name="bordercolor"> "#3344dd" </xsl:attribute> </xsl:attribute-set><xsl:template match="table"> <ebizml> <head> <title>XSLT xsl:element Example</title> </head> <body> <span style="width 600px;border: 2px outset blue solidl;display:block"> </span><br /> <table cellspacing="0" border="1" bordercolor="blue" width="200"> <xsl:for-each select="row"> <tr> <xsl:for-each select="entry"> <td><xsl:apply-templates/></td> </xsl:for-each> </tr> </xsl:for-each> </table> </body> </ebizml> </xsl:template> </xsl:stylesheet> |