You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Wei Cheng <We...@baylor.edu> on 2001/02/13 19:26:54 UTC

contains() question

Hi,all:
   I want to test if some string is a substring of the element in the xml
   document. I attach my xml document and the xsl document as
   following:
   delimeter.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="finddelimeter" > 
  <xsl:variable name="delimeter" select="/doc/employee/name/firstname|/doc/employee/name/lastname|/doc/person/name/firstname|/doc/person/name/lastname"/>
    <xsl:for-each select="$delimeter">
        <xsl:if test="contains($delimeter,'D')"/>
          <ERROR> wrong delimeter </ERROR>
     </xsl:for-each>
  <xsl:variable name="isvalid">
    <xsl:call-template name="finddelimeter"/>
  </xsl:variable>
 </xsl:template>
</xsl:stylesheet>
   foo7.xml
<?xml version="1.0"?>
<doc>
<employee>
<name>
      <firstname> Davi </firstname>
      <lastname> Marston</lastname>
    </name>
    <age> 40 </age>
</employee>
<employee>
 <name>
      <firstname> Donald  </firstname>
      <lastname> Leslie </lastname>
    </name>
    <age> 40 </age>
</employee>
 <name>
      <firstname> Emily  </firstname>
      <lastname> Donohue</lastname>
     </name>
     <age> 34 </age>
<employee>
<name>
      <firstname> Emily  </firstname>
      <lastname> Donohue</lastname>
     </name>
     <age> 35 </age>
</employee>
 <person>
    <name>
      <firstname> David </firstname>
      <lastname> Marston</lastname>
    </name>
    <age> 42 </age>
  </person>    
  <person>
    <name>
      <firstname> Donald  </firstname>
      <lastname> Leslie </lastname>
    </name>
    <age> 40 </age>
  </person> 
  <person>
     <name>
      <firstname> Emily  </firstname>
      <lastname> Donohue</lastname>
     </name>
     <age> 35 </age>
  </person> 
  <person>
    <name>
     <firstname> Myriam  </firstname>
     <lastname> Midy</lastname>
    </name>
     <age> 35 </age>
  </person>
  <person>
     <name>
      <firstname> Emily  </firstname>
      <lastname> Donohue</lastname>
     </name>
     <age> 34 </age>
  </person>
</doc>   
     I want to check if 'D' is a substring of all
      /doc/employee/name/firstname|/doc/employee/name/lastname|/doc/person/name/firstname|/doc/person/name/lastname
      nodeset(), if
      it exists , I can store the true or false value in $isvalid
      but when I apply this xsl to my xml file,it always give the
      wrong answer, i don't know what's wrong with my code?
      thanks for your help!
      Wei