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