1<xsl:transform 2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 version="1.0" 4> 5 6 <!-- Test FileName: mk045.xsl --> 7 <!-- Source Attribution: 8 This test was written by Michael Kay and is taken from 9 'XSLT Programmer's Reference' published by Wrox Press Limited in 2000; 10 ISBN 1-861003-12-9; copyright Wrox Press Limited 2000; all rights reserved. 11 Now updated in the second edition (ISBN 1861005067), http://www.wrox.com. 12 No part of this book may be reproduced, stored in a retrieval system or 13 transmitted in any form or by any means - electronic, electrostatic, mechanical, 14 photocopying, recording or otherwise - without the prior written permission of 15 the publisher, except in the case of brief quotations embodied in critical articles or reviews. 16 --> 17 <!-- Example: shapes.xml, area.xsl --> 18 <!-- Chapter/Page: 7-502 --> 19 <!-- Purpose: Using position() to process node set recursively --> 20 21<xsl:template match="rectangle" mode="area"> 22 <xsl:value-of select="@width * @height"/> 23</xsl:template> 24 25<xsl:template match="square" mode="area"> 26 <xsl:value-of select="@side * @side"/> 27</xsl:template> 28 29<xsl:template match="circle" mode="area"> 30 <xsl:value-of select="3.14159 * @radius * @radius"/> 31</xsl:template> 32 33<xsl:template name="total-area"> 34 <xsl:param name="set-of-shapes"/> 35 <xsl:choose> 36 <xsl:when test="$set-of-shapes"> 37 <xsl:variable name="first"> 38 <xsl:apply-templates select="$set-of-shapes[1]" mode="area"/> 39 </xsl:variable> 40 <xsl:variable name="rest"> 41 <xsl:call-template name="total-area"> 42 <xsl:with-param name="set-of-shapes" 43 select="$set-of-shapes[position()!=1]"/> 44 </xsl:call-template> 45 </xsl:variable> 46 <xsl:value-of select="$first + $rest"/> 47 </xsl:when> 48 <xsl:otherwise>0</xsl:otherwise> 49 </xsl:choose> 50</xsl:template> 51 52<xsl:template match="shapes"> 53 <xsl:call-template name="total-area"> 54 <xsl:with-param name="set-of-shapes" select="*"/> 55 </xsl:call-template> 56</xsl:template> 57 58 59 60 <!-- 61 * Licensed to the Apache Software Foundation (ASF) under one 62 * or more contributor license agreements. See the NOTICE file 63 * distributed with this work for additional information 64 * regarding copyright ownership. The ASF licenses this file 65 * to you under the Apache License, Version 2.0 (the "License"); 66 * you may not use this file except in compliance with the License. 67 * You may obtain a copy of the License at 68 * 69 * http://www.apache.org/licenses/LICENSE-2.0 70 * 71 * Unless required by applicable law or agreed to in writing, software 72 * distributed under the License is distributed on an "AS IS" BASIS, 73 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 74 * See the License for the specific language governing permissions and 75 * limitations under the License. 76 --> 77 78</xsl:transform> 79