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