XSLT apply templates with parameters 

Joined:
03/21/2010
Posts:
49

November 04, 2010 20:08:02    Last update: November 04, 2010 20:45:25
Use the <xsl:with-param> and <xsl:param> tags to apply parameters to XSL stylesheets:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:java="http://xml.apache.org/xslt/java"
    exclude-result-prefixes="java"> <!-- this removes namespace info -->

<xsl:output method="html"/>

<xsl:template match="/">
    <xsl:apply-templates select="event/details">
	<xsl:with-param name="title" select="event/title"/> <!-- pass param "title" to matching templates -->
    </xsl:apply-templates>
</xsl:template>

<xsl:template match="details">
    <xsl:param name="title"/> <!-- this template takes parameter "title" -->
    Title: <xsl:value-of select="$title"/><br/>
    Timestamp: <xsl:value-of select="java:DateUtil.getDate(number(timestamp))"/><br/>
    Description: <xsl:value-of select="description"/><br/>
</xsl:template>

</xsl:stylesheet>
Share |
| Comment  | Tags