1<xsl:stylesheet 2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 version="1.0"> 4 5 <!-- Test FileName: mk052.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: number-list.xml, number-total.xsl --> 17 <!-- Chapter/Page: 8-553 --> 18 <!-- Purpose: Totaling a list of numbers --> 19 20<xsl:template name="total-numbers"> 21 <xsl:param name="list"/> 22 <xsl:variable name="wlist" 23 select="concat(normalize-space($list), ' ')"/> 24 <xsl:choose> 25 <xsl:when test="$wlist!=' '"> 26 <xsl:variable name="first" 27 select="substring-before($wlist, ' ')"/> 28 <xsl:variable name="rest" 29 select="substring-after($wlist, ' ')"/> 30 <xsl:variable name="total"> 31 <xsl:call-template name="total-numbers"> 32 <xsl:with-param name="list" select="$rest"/> 33 </xsl:call-template> 34 </xsl:variable> 35 <xsl:value-of select="number($first) + number($total)"/> 36 </xsl:when> 37 <xsl:otherwise>0</xsl:otherwise> 38 </xsl:choose> 39</xsl:template> 40 41<xsl:template match="/"> 42 <xsl:call-template name="total-numbers"> 43 <xsl:with-param name="list" select="."/> 44 </xsl:call-template> 45</xsl:template> 46 47 48 49 <!-- 50 * Licensed to the Apache Software Foundation (ASF) under one 51 * or more contributor license agreements. See the NOTICE file 52 * distributed with this work for additional information 53 * regarding copyright ownership. The ASF licenses this file 54 * to you under the Apache License, Version 2.0 (the "License"); 55 * you may not use this file except in compliance with the License. 56 * You may obtain a copy of the License at 57 * 58 * http://www.apache.org/licenses/LICENSE-2.0 59 * 60 * Unless required by applicable law or agreed to in writing, software 61 * distributed under the License is distributed on an "AS IS" BASIS, 62 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 63 * See the License for the specific language governing permissions and 64 * limitations under the License. 65 --> 66 67</xsl:stylesheet> 68