English | Français | Deutsch | Magyar | >> 中文 << | Polski ZVON > Tutorials > XSLT Tutorial
>> 页 49 << | 上一条 | 下一条 | 目录 | 元素索引

如果 starts-with 函数的第一个参数开头和第二个参数一致,函数返回真,否则返回假。如果函数 contains 的第一个参数字符串包含第二个参数的字符串,将返回真,否则返回假。

XSLT stylesheet 1

XML源码
<source>

<text>Welcome to XSL world.</text>
<string>Welcome</string>
<string>XSL</string>
<string>XML</string>

</source>

输出
<TABLE border="1">
  <TR>
     <TH colspan="3">Welcome to XSL world.</TH>
  </TR>
  <TR>
     <TH>string</TH>
     <TH>starts-with</TH>
     <TH>contains</TH>
  </TR>
  <TR>
     <TD>Welcome</TD>
     <TD>true</TD>
     <TD>true</TD>
  </TR>
  <TR>
     <TD>XSL</TD>
     <TD>false</TD>
     <TD>true</TD>
  </TR>
  <TR>
     <TD>XML</TD>
     <TD>false</TD>
     <TD>false</TD>
  </TR>
</TABLE>

用HTML察看
Welcome to XSL world.
string starts-with contains
Welcome true true
XSL false true
XML false false
XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE border="1">
          <TR>
               <TH colspan="3">
                    <xsl:value-of select="//text"/>
               </TH>
          </TR>
          <TR>
               <TH>string</TH>
               <TH>starts-with</TH>
               <TH>contains</TH>
          </TR>
          <xsl:for-each select="//string">
               <TR>
                    <TD>
                         <xsl:value-of select="."/>
                    </TD>
                    <TD>
                         <xsl:value-of select="starts-with(//text,.)"/>
                    </TD>
                    <TD>
                         <xsl:value-of select="contains(//text,.)"/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>