1<?xml version="1.0"?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 3 4 <!-- FileName: variable08 --> 5 <!-- Document: http://www.w3.org/TR/xslt --> 6 <!-- DocVersion: 19991116 --> 7 <!-- Section: 11.2 Values of Variables and Parameters --> 8 <!-- Purpose: Test for handling of RTF used as positional index by setting 9 variable as the content of the xsl:variable element. Reference as [position()=$n] 10 This is the case that will NOT obtain what the naive person expects. --> 11 <!-- Author: Paul Dick --> 12 <!-- Note: When a variable is used to select nodes by position, 13 be careful not to do: 14 <xsl:variable name="n">2</xsl:variable> 15 ... 16 <xsl:value-of select="item[$n]"/> 17 This will output the value of the first item element, 18 because the variable n will be bound to a result tree fragment, 19 not a number. Instead, do either 20 21 <xsl:variable name="n" select="2"/> 22 ... 23 <xsl:value-of select="item[$n]"/> 24 or 25 <xsl:variable name="n">2</xsl:variable> 26 ... 27 <xsl:value-of select="item[position()=$n]"/> --> 28 29<xsl:template match="doc"> 30 <xsl:variable name="n">2</xsl:variable> 31 <out> 32 <xsl:value-of select="item[position()=$n]"/> 33 </out> 34</xsl:template> 35 36 37 <!-- 38 * Licensed to the Apache Software Foundation (ASF) under one 39 * or more contributor license agreements. See the NOTICE file 40 * distributed with this work for additional information 41 * regarding copyright ownership. The ASF licenses this file 42 * to you under the Apache License, Version 2.0 (the "License"); 43 * you may not use this file except in compliance with the License. 44 * You may obtain a copy of the License at 45 * 46 * http://www.apache.org/licenses/LICENSE-2.0 47 * 48 * Unless required by applicable law or agreed to in writing, software 49 * distributed under the License is distributed on an "AS IS" BASIS, 50 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 51 * See the License for the specific language governing permissions and 52 * limitations under the License. 53 --> 54 55</xsl:stylesheet> 56