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