1<?xml version="1.0"?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 3 4 <!-- FileName: variable19 --> 5 <!-- Document: http://www.w3.org/TR/xslt --> 6 <!-- DocVersion: 19991116 --> 7 <!-- Section: 11 --> 8 <!-- Purpose: Verify that a variable in an inner template can take on a new value --> 9 <!-- Author: David Marston --> 10 <!-- "Only the innermost binding of a variable is visible." --> 11 12<xsl:template match="/"> 13 <out> 14 <xsl:variable name="var" select="'level0'"/> 15 <xsl:text>begin root template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 16</xsl:text> 17 <xsl:apply-templates/> 18 <xsl:text>end root template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 19</xsl:text> 20 </out> 21</xsl:template> 22 23<xsl:template match="doc"> 24 <xsl:variable name="var" select="'level1'"/> 25 <xsl:text>begin doc template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 26</xsl:text> 27 <xsl:apply-templates/> 28 <xsl:text>end doc template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 29</xsl:text> 30</xsl:template> 31 32<xsl:template match="a"> 33 <xsl:variable name="var" select="@pos"/> 34 <xsl:text>begin a template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 35</xsl:text> 36 <xsl:apply-templates/> 37 <xsl:text>end a template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 38</xsl:text> 39</xsl:template> 40 41<xsl:template match="b"> 42 <xsl:variable name="var" select="'level3'"/> 43 <xsl:text>in b template, $var=</xsl:text><xsl:value-of select="$var"/><xsl:text> 44</xsl:text> 45</xsl:template> 46 47<xsl:template match="text()"/><!-- suppress empty lines --> 48 49 50 <!-- 51 * Licensed to the Apache Software Foundation (ASF) under one 52 * or more contributor license agreements. See the NOTICE file 53 * distributed with this work for additional information 54 * regarding copyright ownership. The ASF licenses this file 55 * to you under the Apache License, Version 2.0 (the "License"); 56 * you may not use this file except in compliance with the License. 57 * You may obtain a copy of the License at 58 * 59 * http://www.apache.org/licenses/LICENSE-2.0 60 * 61 * Unless required by applicable law or agreed to in writing, software 62 * distributed under the License is distributed on an "AS IS" BASIS, 63 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 64 * See the License for the specific language governing permissions and 65 * limitations under the License. 66 --> 67 68</xsl:stylesheet> 69