You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dm...@apache.org on 2002/11/22 21:46:23 UTC

cvs commit: xml-xalan/test/tests/conf/idkey idkey30.xsl idkey30.xml

dmarston    2002/11/22 12:46:23

  Modified:    test/tests/conf/idkey idkey30.xsl idkey30.xml
  Log:
  New approach to testing generate-id() where strings are checked
  internally for uniqueness but not sent to output.
  
  Revision  Changes    Path
  1.2       +81 -44    xml-xalan/test/tests/conf/idkey/idkey30.xsl
  
  Index: idkey30.xsl
  ===================================================================
  RCS file: /home/cvs/xml-xalan/test/tests/conf/idkey/idkey30.xsl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- idkey30.xsl	15 Dec 2000 19:34:34 -0000	1.1
  +++ idkey30.xsl	22 Nov 2002 20:46:23 -0000	1.2
  @@ -6,54 +6,91 @@
     <!-- DocVersion: 19991116 -->
     <!-- Section: 12.4 Miscellaneous Additional Functions  -->
     <!-- Creator: David Marston -->
  -  <!-- Purpose: Test of 'generate-id()' on various kinds of nodes -->
  -  <!-- Results will vary by processor. -->
  +  <!-- Purpose: Test that 'generate-id()' on various kinds of nodes yields unique values for each -->
   
  -<xsl:template match="/doc">
  +<xsl:output method="xml" encoding="UTF-8" indent="no"/>
  +
  +<xsl:template match="doc">
     <out>
  -    <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
  +    <!-- Get in position so we have nodes on the following axis. -->
  +    <xsl:apply-templates select="side"/>
     </out>
   </xsl:template>
   
  -<xsl:template match="*"><!-- for child elements -->
  -  <xsl:text>
  -  E(</xsl:text>
  -  <xsl:value-of select="name()"/>
  -  <xsl:text>):</xsl:text>
  -  <xsl:value-of select="generate-id()"/>
  -  <xsl:text> has </xsl:text>
  -  <xsl:apply-templates select="@*"/>
  -  <xsl:apply-templates/>
  -  <xsl:text>
  -</xsl:text>
  -</xsl:template>
  -
  -<xsl:template match="@*">
  -  <xsl:text>A(</xsl:text>
  -  <xsl:value-of select="name()"/>
  -  <xsl:text>):</xsl:text>
  -  <xsl:value-of select="generate-id()"/>
  -  <xsl:text>;</xsl:text>
  -</xsl:template>
  -
  -<xsl:template match="text()">
  -  <xsl:text>T:</xsl:text>
  -  <xsl:value-of select="generate-id()"/>
  -  <xsl:text>,</xsl:text>
  -</xsl:template>
  -
  -<xsl:template match="comment()">
  -  <xsl:text>C:</xsl:text>
  -  <xsl:value-of select="generate-id()"/>
  -  <xsl:text>,</xsl:text>
  -</xsl:template>
  -
  -<xsl:template match="processing-instruction()">
  -  <xsl:text>P(</xsl:text>
  -  <xsl:value-of select="name()"/>
  -  <xsl:text>):</xsl:text>
  -  <xsl:value-of select="generate-id()"/>
  -  <xsl:text>;</xsl:text>
  +<xsl:template match="side">
  +  <!-- Build up a string containing generated IDs for nodes on the following axis, plus attributes they carry. -->
  +  <xsl:variable name="accumulated">
  +    <!-- Since call-template doesn't change context, iterate by position number. -->
  +    <xsl:call-template name="nextnode">
  +      <xsl:with-param name="this" select="1" />
  +      <xsl:with-param name="max" select="count(following::node()|following::*/@*)" />
  +      <xsl:with-param name="idset" select="'+'" />
  +      <!-- Use + as delimiter to avoid spoofs from adjacent strings.
  +           Returned string from generate-id() can't contain +. -->
  +    </xsl:call-template>
  +  </xsl:variable>
  +  <!-- Summary data, so we have output when we pass. -->
  +  <xsl:text>Number of IDs accumulated: </xsl:text>
  +  <xsl:value-of select="count(following::node()|following::*/@*)"/>
  +  <!-- Now, take one node of each kind, whose generated ID should not be in the accumulated string,
  +    surround generated ID by + to avoid substring matches, and see if it's in there. -->
  +  <!-- Now see if we duplicated an ID with the root -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(/),'+'))">
  +    <xsl:text>FAIL on root node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(/)"/>
  +  </xsl:if>
  +  <!-- Now see if we duplicated an ID with the element -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(.),'+'))">
  +    <xsl:text>FAIL on side node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(.)"/>
  +  </xsl:if>
  +  <!-- Now see if we duplicated an ID with the attribute -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(./@att),'+'))">
  +    <xsl:text>FAIL on side/@att node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(./@att)"/>
  +  </xsl:if>
  +  <!-- Now see if we duplicated an ID with the text node -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(./text()),'+'))">
  +    <xsl:text>FAIL on side/text() node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(./text())"/>
  +  </xsl:if>
  +  <!-- Now see if we duplicated an ID with the comment node -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(./comment()),'+'))">
  +    <xsl:text>FAIL on side/comment() node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(./comment())"/>
  +  </xsl:if>
  +  <!-- Now see if we duplicated an ID with the PI node -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(./processing-instruction('s-pi')),'+'))">
  +    <xsl:text>FAIL on side/processing-instruction('s-pi') node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(./processing-instruction('s-pi'))"/>
  +  </xsl:if>
  +  <!-- Now see if we duplicated an ID with a namespace node -->
  +  <xsl:if test="contains($accumulated,concat('+',generate-id(./namespace::*[1]),'+'))">
  +    <xsl:text>FAIL on side/namespace::*[1] node whose ID is </xsl:text>
  +    <xsl:value-of select="generate-id(./namespace::*[1])"/>
  +  </xsl:if>
  +</xsl:template>
  +
  +<xsl:template name="nextnode">
  +  <xsl:param name="this"/>
  +  <xsl:param name="max"/>
  +  <xsl:param name="idset"/>
  +  <!-- Params this and max are index numbers, idset is the string we're accumulating. -->
  +  <xsl:variable name="this-id" select="generate-id((following::node()|following::*/@*)[position() = $this])"/>
  +  <xsl:choose>
  +    <xsl:when test="$this &lt;= $max">
  +      <!-- Recurse, adding current ID to string of all IDs on "begin" sub-tree, with separators -->
  +      <xsl:call-template name="nextnode">
  +        <xsl:with-param name="this" select="$this+1" />
  +        <xsl:with-param name="max" select="$max" />
  +        <xsl:with-param name="idset" select="concat($idset,$this-id,'+')" />
  +      </xsl:call-template>
  +    </xsl:when>
  +    <xsl:otherwise>
  +      <!-- "return" the final idset -->
  +      <xsl:value-of select="$idset"/>
  +    </xsl:otherwise>
  +  </xsl:choose>
   </xsl:template>
   
  -</xsl:stylesheet>
  +</xsl:stylesheet>
  \ No newline at end of file
  
  
  
  1.2       +9 -7      xml-xalan/test/tests/conf/idkey/idkey30.xml
  
  Index: idkey30.xml
  ===================================================================
  RCS file: /home/cvs/xml-xalan/test/tests/conf/idkey/idkey30.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- idkey30.xml	15 Dec 2000 19:34:34 -0000	1.1
  +++ idkey30.xml	22 Nov 2002 20:46:23 -0000	1.2
  @@ -1,12 +1,14 @@
   <?xml version="1.0"?> 
  -<doc att="top">
  -  <?a-pi some data?>
  -  <!-- This is the 1st comment -->
  -  text-in-doc
  +<doc>
  +  <side att="view"><!-- This is the side comment -->text-in-side<?s-pi side ?></side>
  +  <begin bat="top"><?a-pi some data?>
  +  <!-- This is the 2nd comment -->
  +  text-in-begin
     <inner blat="blob">
       inner-text
  -    <!-- This is the 2nd comment -->
  -    <sub>subtext</sub>
  +    <!-- This is the 3rd comment -->
  +    <sub latte="glub">subtext</sub>
     </inner>
  -  text-in-doc2
  +  text-in-begin2
  +  </begin>
   </doc>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org