xref: /aosp_15_r20/external/apache-xml/test/tests/conf/idkey/idkey50.xsl (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<?xml version="1.0"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3     version='1.0'
4     xmlns:x="http://namespaces.ogbuji.net/articles" exclude-result-prefixes="x">
5
6  <!-- FileName: idkey50 -->
7  <!-- Document: http://www.w3.org/TR/xslt -->
8  <!-- DocVersion: 19991116 -->
9  <!-- Section: 12.2 -->
10  <!-- Creator: Uche Ogbuji, adapted by David Marston -->
11  <!-- Purpose: Test combination of key() and document() reading from stylesheet. -->
12  <!-- Elaboration: "Look-up table 1.6 is worth a close look because it uses an advanced XSLT
13    technique. It builds up the lookup-table right in the stylesheet, using a distinct namespace.
14    You can see the x:ns-to-binding elements right below the key. If you are familiar with keys,
15    you are aware that they define indices that will be built on the nodes in the original source
16    document that match the pattern in the match attribute. What is not as well known is that
17    every time an additional source document is loaded with the XSLT document() function, all keys
18    are applied to it as well. The xsl:variable...uses a special form of document() call to load
19    the stylesheet itself as an additional source document. Thus the nodes in the stylesheet that
20    match the ns-to-binding are indexed. This is a very useful technique for setting up a look-up
21    table without having to hack at the source document or depend on an additional file." -->
22
23<xsl:output method='xml'/>
24
25  <!-- Lookup table 1.6: WSDL binding types -->
26  <xsl:key name='ns-to-binding' match='x:ns-to-binding' use='@binding'/>
27  <x:ns-to-binding uri='http://schemas.xmlsoap.org/wsdl/soap/' binding='SOAP'/>
28  <x:ns-to-binding uri='http://schemas.xmlsoap.org/wsdl/mime/' binding='MIME'/>
29  <x:ns-to-binding uri='http://schemas.xmlsoap.org/wsdl/http/' binding='HTTP'/>
30
31<xsl:template match='doc'>
32  <out>
33    <xsl:apply-templates/>
34  </out>
35</xsl:template>
36
37<xsl:template match="bind">
38  <bound>
39    <xsl:variable name="lookup" select="."/>
40    <xsl:value-of select="$lookup"/><xsl:text>- </xsl:text>
41    <xsl:for-each select="document('')"><!-- Switch context so key reads from stylesheet -->
42      <xsl:value-of select="key('ns-to-binding',$lookup)/@uri"/>
43    </xsl:for-each>
44  </bound>
45</xsl:template>
46
47
48  <!--
49   * Licensed to the Apache Software Foundation (ASF) under one
50   * or more contributor license agreements. See the NOTICE file
51   * distributed with this work for additional information
52   * regarding copyright ownership. The ASF licenses this file
53   * to you under the Apache License, Version 2.0 (the  "License");
54   * you may not use this file except in compliance with the License.
55   * You may obtain a copy of the License at
56   *
57   *     http://www.apache.org/licenses/LICENSE-2.0
58   *
59   * Unless required by applicable law or agreed to in writing, software
60   * distributed under the License is distributed on an "AS IS" BASIS,
61   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
62   * See the License for the specific language governing permissions and
63   * limitations under the License.
64  -->
65
66</xsl:stylesheet>
67