starts-with() 関数  
最初のパラメータ文字列が 2 番目のパラメータ文字列で始まるかどうかを調べます。
 
入力

2 つの文字列。

 
出力

最初の文字列が 2 番目の文字列で始まる場合、starts-with() はブール値 true を返します。それ以外の場合は false を返します。

 
定義先

XPath 4.2 節「文字列関数」

 

次のサンプル XML ドキュメントを使用します。

<?xml version="1.0"?>
<list>
  <title>A few of my favorite albums</title>
  <listitem>A Love Supreme</listitem>
  <listitem>Beat Crazy</listitem>
  <listitem>Here Come the Warm Jets</listitem>
  <listitem>Kind of Blue</listitem>
  <listitem>London Calling</listitem>
  <listitem>Remain in Light</listitem>
  <listitem>The Joshua Tree</listitem>
  <listitem>The Indestructible Beat of Soweto</listitem>
</list>

このスタイルシートは、文字列 "The" で始まるすべての <listitem> 要素のコンテンツを出力します。

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text"/>

  <xsl:variable name="newline">
<xsl:text>
</xsl:text>
  </xsl:variable>

  <xsl:template match="/">
    <xsl:value-of select="$newline"/>
    <xsl:for-each select="list/listitem">
      <xsl:if test="starts-with(., 'The')">
        <xsl:value-of select="position()"/>
        <xsl:text>. </xsl:text>
        <xsl:value-of select="."/>
        <xsl:value-of select="$newline"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

スタイルシートからは、次のような結果が生成されます。


7. The Joshua Tree
8. The Indestructible Beat of Soweto