The <xsl:with-param> element has the same content model and declares a variable in the same manner as <xsl:variable> and <xsl:param>. However, <xsl:with-param> must be used inside either <xsl:apply-templates> or <xsl:call-template>, and using it replaces the value of the variable that was declared using the original <xsl:param>. If there is no <xsl:param> declaration in the template being called, the variable is ignored. The <xsl:with-param> element cannot be used to change the value of a variable declared with <xsl:variable>.
STYLESHEET: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="text()"/> <xsl:template match="thoroughfare"> <xsl:apply-templates select="block"> <xsl:with-param name="precinct" select="5"/> </xsl:apply-templates> </xsl:template> <xsl:template match="block"> <xsl:param name="precinct" select="4"/> Precinct: <xsl:value-of select="$precinct"/> Block name: <xsl:value-of select="text()"/> </xsl:template> </xsl:stylesheet> OUTPUT: Precinct: 5 Block name: 1st Street Precinct: 5 Block name: 2nd Street Precinct: 5 Block name: 3rd Street Precinct: 5 Block name: First Street Precinct: 5 Block name: Second Street Precinct: 5 Block name: Third Street Precinct: 4 Block name: Panorama Street Precinct: 4 Block name: Highland Plaza Precinct: 4 Block name: Hutchens Avenue Precinct: 4 Block name: Wildwood Drive Precinct: 4 Block name: Old Chimney Road Precinct: 4 Block name: Carrol Circle |