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