xref: /aosp_15_r20/external/apache-xml/test/tests/contrib/xsltc/schemasoft/bottles.xsl (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<?xml version="1.0"?>
2
3<!--
4
5     File:       bottles.xsl
6
7     Purpose:    XSL Version of 99 Bottles of Beer
8
9     Author:     Chris Rathman 1/10/2001
10
11     Desc:       Transform bottles.xml into output text stream
12
13     Tested:     Xalan Version 1.1 and Saxon 5.4.1
14
15-->
16
17<xsl:stylesheet
18
19   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20
21   version="1.0">
22
23
24
25<xsl:output method="text"/>
26
27
28
29<!-- function to return the number of bottles as a string -->
30
31<xsl:template name="item">
32
33<xsl:param name="n"/>
34
35
36
37<!-- n bottles -->
38
39<xsl:if test="$n > 1">
40
41<xsl:value-of select="$n"/>
42
43<xsl:text> </xsl:text>
44
45<xsl:value-of select="*/container-plural"/>
46
47</xsl:if>
48
49
50
51<!-- 1 bottle -->
52
53<xsl:if test="$n = 1">
54
55<xsl:value-of select="$n"/>
56
57<xsl:text> </xsl:text>
58
59<xsl:value-of select="*/container-singular"/>
60
61</xsl:if>
62
63
64
65<!-- No more -->
66
67<xsl:if test="$n = 0">
68
69<xsl:text>No more </xsl:text>
70
71<xsl:value-of select="*/container-plural"/>
72
73</xsl:if>
74
75
76
77<!-- of beer -->
78
79<xsl:text> of </xsl:text>
80
81<xsl:value-of select="*/item"/>
82
83</xsl:template>
84
85
86
87<!-- recursive function to sing the verses of the song -->
88
89<xsl:template name="sing">
90
91<xsl:param name="quantity"/>
92
93
94
95<!-- get the current number of bottles as a string -->
96
97<xsl:variable name="itemname">
98
99<xsl:call-template name="item">
100
101<xsl:with-param name="n" select="$quantity"/>
102
103</xsl:call-template>
104
105</xsl:variable>
106
107
108
109<!-- get the number of bottles after taking one down -->
110
111<xsl:variable name="itemnext">
112
113<xsl:call-template name="item">
114
115<xsl:with-param name="n" select="$quantity - 1"/>
116
117</xsl:call-template>
118
119</xsl:variable>
120
121
122
123<!-- "n bottles of beer on the wall," -->
124
125<xsl:value-of select="$itemname"/>
126
127<xsl:text> </xsl:text>
128
129<xsl:value-of select="*/location"/>
130
131<xsl:text>,&#xA;</xsl:text>
132
133
134
135<!-- "n bottles of beer," -->
136
137<xsl:value-of select="$itemname"/>
138
139<xsl:text>,&#xA;</xsl:text>
140
141
142
143<!-- "You take one down, pass it around," -->
144
145<xsl:value-of select="*/retrieve"/>
146
147<xsl:text>, </xsl:text>
148
149<xsl:value-of select="*/distribute"/>
150
151<xsl:text>,&#xA;</xsl:text>
152
153
154
155<!--" n-1 bottles of beer on the wall." -->
156
157<xsl:value-of select="$itemnext"/>
158
159<xsl:text> </xsl:text>
160
161<xsl:value-of select="*/location"/>
162
163<xsl:text>.&#xA;&#xA;</xsl:text>
164
165
166
167<!-- recurse to the next bottle of beer -->
168
169<xsl:if test="$quantity != 1">
170
171<xsl:call-template name="sing">
172
173<xsl:with-param name="quantity" select="$quantity - 1"/>
174
175</xsl:call-template>
176
177</xsl:if>
178
179</xsl:template>
180
181
182
183<!-- output the song based on the xml input parameters -->
184
185<xsl:template match="/">
186
187<xsl:text>&#xA;&#xA;</xsl:text>
188
189<xsl:call-template name="sing">
190
191<xsl:with-param name="quantity" select="*/quantity"/>
192
193</xsl:call-template>
194
195</xsl:template>
196
197  <!--
198   * Licensed to the Apache Software Foundation (ASF) under one
199   * or more contributor license agreements. See the NOTICE file
200   * distributed with this work for additional information
201   * regarding copyright ownership. The ASF licenses this file
202   * to you under the Apache License, Version 2.0 (the  "License");
203   * you may not use this file except in compliance with the License.
204   * You may obtain a copy of the License at
205   *
206   *     http://www.apache.org/licenses/LICENSE-2.0
207   *
208   * Unless required by applicable law or agreed to in writing, software
209   * distributed under the License is distributed on an "AS IS" BASIS,
210   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
211   * See the License for the specific language governing permissions and
212   * limitations under the License.
213  -->
214
215</xsl:stylesheet>
216