xref: /aosp_15_r20/external/apache-xml/test/tests/contrib/xsltc/mk/mk012.xsl (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<xsl:transform
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 version="1.0"
4>
5
6  <!-- Test FileName: mk012.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, longest-speech.xsl -->
18  <!-- Chapter/Page: 4-171 -->
19  <!-- Purpose: Using recursion to process a node set -->
20
21<xsl:template name="max">
22<xsl:param name="list"/>
23<xsl:choose>
24<xsl:when test="$list">
25   <xsl:variable name="first" select="count($list[1]/LINE)"/>
26   <xsl:variable name="max-of-rest">
27      <xsl:call-template name="max">
28         <xsl:with-param name="list" select="$list[position()!=1]"/>
29      </xsl:call-template>
30   </xsl:variable>
31   <xsl:choose>
32   <xsl:when test="$first &gt; $max-of-rest">
33      <xsl:value-of select="$first"/>
34   </xsl:when>
35   <xsl:otherwise>
36      <xsl:value-of select="$max-of-rest"/>
37   </xsl:otherwise>
38   </xsl:choose>
39</xsl:when>
40<xsl:otherwise>0</xsl:otherwise>
41</xsl:choose>
42</xsl:template>
43
44<xsl:template match="/">
45Longest speech is <xsl:text/>
46	<xsl:call-template name="max">
47        <xsl:with-param name="list" select="//SPEECH"/>
48	</xsl:call-template>
49<xsl:text/> lines.
50</xsl:template>
51
52
53
54  <!--
55   * Licensed to the Apache Software Foundation (ASF) under one
56   * or more contributor license agreements. See the NOTICE file
57   * distributed with this work for additional information
58   * regarding copyright ownership. The ASF licenses this file
59   * to you under the Apache License, Version 2.0 (the  "License");
60   * you may not use this file except in compliance with the License.
61   * You may obtain a copy of the License at
62   *
63   *     http://www.apache.org/licenses/LICENSE-2.0
64   *
65   * Unless required by applicable law or agreed to in writing, software
66   * distributed under the License is distributed on an "AS IS" BASIS,
67   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68   * See the License for the specific language governing permissions and
69   * limitations under the License.
70  -->
71
72</xsl:transform>
73