xref: /aosp_15_r20/external/apache-xml/test/tests/conf/idkey/idkey31.xsl (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1*1212f9a0SAndroid Build Coastguard Worker<?xml version="1.0" encoding="UTF-8"?>
2*1212f9a0SAndroid Build Coastguard Worker<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3*1212f9a0SAndroid Build Coastguard Worker
4*1212f9a0SAndroid Build Coastguard Worker  <!-- FileName: idkey31 -->
5*1212f9a0SAndroid Build Coastguard Worker  <!-- Document: http://www.w3.org/TR/xslt -->
6*1212f9a0SAndroid Build Coastguard Worker  <!-- DocVersion: 19991116 -->
7*1212f9a0SAndroid Build Coastguard Worker  <!-- Section: 12.4 Miscellaneous Additional Functions  -->
8*1212f9a0SAndroid Build Coastguard Worker  <!-- Creator: David Marston -->
9*1212f9a0SAndroid Build Coastguard Worker  <!-- Purpose: Test of 'generate-id()' on namespace nodes -->
10*1212f9a0SAndroid Build Coastguard Worker
11*1212f9a0SAndroid Build Coastguard Worker<xsl:output method="xml" encoding="UTF-8" indent="no"/>
12*1212f9a0SAndroid Build Coastguard Worker
13*1212f9a0SAndroid Build Coastguard Worker<xsl:template match="/">
14*1212f9a0SAndroid Build Coastguard Worker  <out>
15*1212f9a0SAndroid Build Coastguard Worker  <!-- Build up a string containing generated IDs for nodes on the namespace axes of self and all lower elements. -->
16*1212f9a0SAndroid Build Coastguard Worker  <xsl:variable name="accumulated">
17*1212f9a0SAndroid Build Coastguard Worker    <!-- Since call-template doesn't change context, iterate by position number. -->
18*1212f9a0SAndroid Build Coastguard Worker    <xsl:call-template name="nextnode">
19*1212f9a0SAndroid Build Coastguard Worker      <xsl:with-param name="this" select="1" />
20*1212f9a0SAndroid Build Coastguard Worker      <xsl:with-param name="max" select="count(descendant-or-self::*/namespace::*)" />
21*1212f9a0SAndroid Build Coastguard Worker      <xsl:with-param name="idset" select="'+'" />
22*1212f9a0SAndroid Build Coastguard Worker      <!-- Use + as delimiter to avoid spoofs from adjacent strings.
23*1212f9a0SAndroid Build Coastguard Worker           Returned string from generate-id() can't contain +. -->
24*1212f9a0SAndroid Build Coastguard Worker    </xsl:call-template>
25*1212f9a0SAndroid Build Coastguard Worker  </xsl:variable>
26*1212f9a0SAndroid Build Coastguard Worker  <!-- Summary data, so we have output when we pass. -->
27*1212f9a0SAndroid Build Coastguard Worker  <xsl:text>Number of IDs accumulated: </xsl:text>
28*1212f9a0SAndroid Build Coastguard Worker  <xsl:value-of select="count(descendant-or-self::*/namespace::*)"/>
29*1212f9a0SAndroid Build Coastguard Worker  <!-- Now, take one node of each kind, whose generated ID should not be in the accumulated string,
30*1212f9a0SAndroid Build Coastguard Worker    surround generated ID by + to avoid substring matches, and see if it's in there. -->
31*1212f9a0SAndroid Build Coastguard Worker  <!-- Now see if we duplicated an ID with the root -->
32*1212f9a0SAndroid Build Coastguard Worker  <xsl:if test="contains($accumulated,concat('+',generate-id(/),'+'))">
33*1212f9a0SAndroid Build Coastguard Worker    <xsl:text>FAIL on root node whose ID is </xsl:text>
34*1212f9a0SAndroid Build Coastguard Worker    <xsl:value-of select="generate-id(/)"/>
35*1212f9a0SAndroid Build Coastguard Worker  </xsl:if>
36*1212f9a0SAndroid Build Coastguard Worker  <!-- Now see if we duplicated an ID with the element -->
37*1212f9a0SAndroid Build Coastguard Worker  <xsl:if test="contains($accumulated,concat('+',generate-id(.),'+'))">
38*1212f9a0SAndroid Build Coastguard Worker    <xsl:text>FAIL on side node whose ID is </xsl:text>
39*1212f9a0SAndroid Build Coastguard Worker    <xsl:value-of select="generate-id(.)"/>
40*1212f9a0SAndroid Build Coastguard Worker  </xsl:if>
41*1212f9a0SAndroid Build Coastguard Worker  <!-- Now see if we duplicated an ID with the attribute -->
42*1212f9a0SAndroid Build Coastguard Worker  <xsl:if test="contains($accumulated,concat('+',generate-id(./@att),'+'))">
43*1212f9a0SAndroid Build Coastguard Worker    <xsl:text>FAIL on side/@att node whose ID is </xsl:text>
44*1212f9a0SAndroid Build Coastguard Worker    <xsl:value-of select="generate-id(./@att)"/>
45*1212f9a0SAndroid Build Coastguard Worker  </xsl:if>
46*1212f9a0SAndroid Build Coastguard Worker  <!-- Now see if we duplicated an ID with the text node -->
47*1212f9a0SAndroid Build Coastguard Worker  <xsl:if test="contains($accumulated,concat('+',generate-id(./text()),'+'))">
48*1212f9a0SAndroid Build Coastguard Worker    <xsl:text>FAIL on side/text() node whose ID is </xsl:text>
49*1212f9a0SAndroid Build Coastguard Worker    <xsl:value-of select="generate-id(./text())"/>
50*1212f9a0SAndroid Build Coastguard Worker  </xsl:if>
51*1212f9a0SAndroid Build Coastguard Worker  <!-- Now see if we duplicated an ID with the comment node -->
52*1212f9a0SAndroid Build Coastguard Worker  <xsl:if test="contains($accumulated,concat('+',generate-id(./comment()),'+'))">
53*1212f9a0SAndroid Build Coastguard Worker    <xsl:text>FAIL on side/comment() node whose ID is </xsl:text>
54*1212f9a0SAndroid Build Coastguard Worker    <xsl:value-of select="generate-id(./comment())"/>
55*1212f9a0SAndroid Build Coastguard Worker  </xsl:if>
56*1212f9a0SAndroid Build Coastguard Worker  <!-- Now see if we duplicated an ID with the PI node -->
57*1212f9a0SAndroid Build Coastguard Worker  <xsl:if test="contains($accumulated,concat('+',generate-id(./processing-instruction('s-pi')),'+'))">
58*1212f9a0SAndroid Build Coastguard Worker    <xsl:text>FAIL on side/processing-instruction('s-pi') node whose ID is </xsl:text>
59*1212f9a0SAndroid Build Coastguard Worker    <xsl:value-of select="generate-id(./processing-instruction('s-pi'))"/>
60*1212f9a0SAndroid Build Coastguard Worker  </xsl:if>
61*1212f9a0SAndroid Build Coastguard Worker  </out>
62*1212f9a0SAndroid Build Coastguard Worker</xsl:template>
63*1212f9a0SAndroid Build Coastguard Worker
64*1212f9a0SAndroid Build Coastguard Worker<xsl:template name="nextnode">
65*1212f9a0SAndroid Build Coastguard Worker  <xsl:param name="this"/>
66*1212f9a0SAndroid Build Coastguard Worker  <xsl:param name="max"/>
67*1212f9a0SAndroid Build Coastguard Worker  <xsl:param name="idset"/>
68*1212f9a0SAndroid Build Coastguard Worker  <!-- Params this and max are index numbers, idset is the string we're accumulating. -->
69*1212f9a0SAndroid Build Coastguard Worker  <xsl:variable name="this-id" select="generate-id((descendant-or-self::*/namespace::*)[position() = $this])"/>
70*1212f9a0SAndroid Build Coastguard Worker  <xsl:choose>
71*1212f9a0SAndroid Build Coastguard Worker    <xsl:when test="$this &lt;= $max">
72*1212f9a0SAndroid Build Coastguard Worker      <!-- Recurse, adding current ID to string of all IDs of namespace nodes, with separators -->
73*1212f9a0SAndroid Build Coastguard Worker      <xsl:call-template name="nextnode">
74*1212f9a0SAndroid Build Coastguard Worker        <xsl:with-param name="this" select="$this+1" />
75*1212f9a0SAndroid Build Coastguard Worker        <xsl:with-param name="max" select="$max" />
76*1212f9a0SAndroid Build Coastguard Worker        <xsl:with-param name="idset" select="concat($idset,$this-id,'+')" />
77*1212f9a0SAndroid Build Coastguard Worker      </xsl:call-template>
78*1212f9a0SAndroid Build Coastguard Worker    </xsl:when>
79*1212f9a0SAndroid Build Coastguard Worker    <xsl:otherwise>
80*1212f9a0SAndroid Build Coastguard Worker      <!-- "return" the final idset -->
81*1212f9a0SAndroid Build Coastguard Worker      <xsl:value-of select="$idset"/>
82*1212f9a0SAndroid Build Coastguard Worker    </xsl:otherwise>
83*1212f9a0SAndroid Build Coastguard Worker  </xsl:choose>
84*1212f9a0SAndroid Build Coastguard Worker</xsl:template>
85*1212f9a0SAndroid Build Coastguard Worker
86*1212f9a0SAndroid Build Coastguard Worker
87*1212f9a0SAndroid Build Coastguard Worker  <!--
88*1212f9a0SAndroid Build Coastguard Worker   * Licensed to the Apache Software Foundation (ASF) under one
89*1212f9a0SAndroid Build Coastguard Worker   * or more contributor license agreements. See the NOTICE file
90*1212f9a0SAndroid Build Coastguard Worker   * distributed with this work for additional information
91*1212f9a0SAndroid Build Coastguard Worker   * regarding copyright ownership. The ASF licenses this file
92*1212f9a0SAndroid Build Coastguard Worker   * to you under the Apache License, Version 2.0 (the  "License");
93*1212f9a0SAndroid Build Coastguard Worker   * you may not use this file except in compliance with the License.
94*1212f9a0SAndroid Build Coastguard Worker   * You may obtain a copy of the License at
95*1212f9a0SAndroid Build Coastguard Worker   *
96*1212f9a0SAndroid Build Coastguard Worker   *     http://www.apache.org/licenses/LICENSE-2.0
97*1212f9a0SAndroid Build Coastguard Worker   *
98*1212f9a0SAndroid Build Coastguard Worker   * Unless required by applicable law or agreed to in writing, software
99*1212f9a0SAndroid Build Coastguard Worker   * distributed under the License is distributed on an "AS IS" BASIS,
100*1212f9a0SAndroid Build Coastguard Worker   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101*1212f9a0SAndroid Build Coastguard Worker   * See the License for the specific language governing permissions and
102*1212f9a0SAndroid Build Coastguard Worker   * limitations under the License.
103*1212f9a0SAndroid Build Coastguard Worker  -->
104*1212f9a0SAndroid Build Coastguard Worker
105*1212f9a0SAndroid Build Coastguard Worker</xsl:stylesheet>
106