1<xsl:transform 2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 version="1.0" 4> 5 6 <!-- Test FileName: mk011.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: scene.xml, naming-lines.xsl --> 18 <!-- Chapter/Page: 4-173 --> 19 <!-- Purpose: Using recursion to process a separated string --> 20 21<xsl:variable name="speakers" select="//SPEAKER"/> 22 23<xsl:template name="contains-name"> 24 <xsl:param name="line"/> 25 <xsl:variable name="line1" 26 select="translate($line, 'abcdefghijklmnopqrstuvwxyz.,:?!;', 27 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ')"/> 28 <xsl:variable name="line2" select="concat(normalize-space($line1), ' ')"/> 29 <xsl:variable name="first" select="substring-before($line2,' ')"/> 30 <xsl:choose> 31 <xsl:when test="$first"> 32 <xsl:choose> 33 <xsl:when test="$speakers[.=$first]">true</xsl:when> 34 <xsl:otherwise> 35 <xsl:variable name="rest" select="substring-after($line2,' ')"/> 36 <xsl:call-template name="contains-name"> 37 <xsl:with-param name="line" select="$rest"/> 38 </xsl:call-template> 39 </xsl:otherwise> 40 </xsl:choose> 41 </xsl:when> 42 <xsl:otherwise>false</xsl:otherwise> 43 </xsl:choose> 44</xsl:template> 45 46<xsl:template match="/"> 47 48<xsl:for-each select="//LINE"> 49 <xsl:variable name="contains-name"> 50 <xsl:call-template name="contains-name"> 51 <xsl:with-param name="line" select="."/> 52 </xsl:call-template> 53 </xsl:variable> 54 <xsl:if test="$contains-name='true'"> 55 <xsl:copy-of select="."/>; 56 </xsl:if> 57</xsl:for-each> 58</xsl:template> 59 60 61 62 <!-- 63 * Licensed to the Apache Software Foundation (ASF) under one 64 * or more contributor license agreements. See the NOTICE file 65 * distributed with this work for additional information 66 * regarding copyright ownership. The ASF licenses this file 67 * to you under the Apache License, Version 2.0 (the "License"); 68 * you may not use this file except in compliance with the License. 69 * You may obtain a copy of the License at 70 * 71 * http://www.apache.org/licenses/LICENSE-2.0 72 * 73 * Unless required by applicable law or agreed to in writing, software 74 * distributed under the License is distributed on an "AS IS" BASIS, 75 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 76 * See the License for the specific language governing permissions and 77 * limitations under the License. 78 --> 79 80</xsl:transform> 81