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