Style_Sheets

Applying Style

Applying Style One model for applying style is to allow the process to run recursively, driven primarily by the document. A series of templates is created, such that there is a template to match each context, then these templates are recursively applied starting at the root of the document. • <xsl:template> <xsl:template match=”section/title”> <h2><xsl:apply-templates/></h2> </xsl:template> …

Applying Style Read More »

Applying Style Procedurally

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> …

Applying Style Procedurally Read More »

Named Template Example

Named Template Example namedtemplate.xml <?xml version=”1.0″ encoding=”iso-8859-1″?> <?xml-stylesheet type=”text/xsl” href=”named_temp_example.xsl”?> <chapter> <warning> <para>Using a damaged extension cord may cause a fire.</para> </warning> <caution> <para>Freshly brewed coffee is hot.</para> </caution> </chapter> namedtemplate.xsl <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”html” encoding=”iso-8859-1″ /> <xsl:template name=”admonition”> <xsl:param name=”type”>Warning</xsl:param> <table border=”1″> <tr><th><xsl:value-of select=”$type”/>:</th></tr> <tr><td><xsl:apply-templates/></td></tr> </table> </xsl:template> <xsl:template match=”warning”> <xsl:call-template name=”admonition”/> </xsl:template> <xsl:template …

Named Template Example Read More »

Conditional Processing

Conditional Processing The xsl:if element evaluates an expression which returns a Boolean result to determine if a template should be instantiated. The evaluation is a simple True or False test on a defined condition or a set of conditions. If the test returns True, the template is applied and the results are displayed in the output. If False, the template is not applied (i.e., …

Conditional Processing Read More »