function-available() 関数  
指定された関数が XSLT プロセッサに対して利用できるかどうかを調べます。この関数を使用すると、XML ドキュメントを処理するために特定の関数が利用できない場合でも、正しく応答するスタイルシートを設計できます。
 
入力

名前関数の名前。通常、この名前は名前空間を使用して設定します。関数名の名前空間が null でない場合、その関数は拡張関数です。それ以外の場合、関数は XSLT または XPath 仕様で定義されている関数の 1 つです。

 
出力

関数が利用できる場合はブール値 true、それ以外の場合は false

 
定義先

XSLT 15 節「Fallback」

 

次の XML ドキュメントを使用して function-available() 関数をテストします。

<?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>

スタイルシートは次のとおりです。

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:jpeg="class:JPEGWriter"
  extension-element-prefixes="jpeg">

  <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:choose>
        <xsl:when test="function-available('jpeg:createJPEG')"> 
          <xsl:value-of 
            select="jpeg:createJPEG(., 'bg.jpg', 
            concat('album', position(), '.jpg'), 
            'Swiss 721 Bold Condensed', 'BOLD', 22, 52, 35)"/>
          <xsl:text>See the file </xsl:text>
          <xsl:value-of select="concat('album', position(), '.jpg')"/>
          <xsl:text> to see the title of album #</xsl:text>
          <xsl:value-of select="position()"/>
          <xsl:value-of select="$newline"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="position()"/>
          <xsl:text>. </xsl:text>
          <xsl:value-of select="."/>
          <xsl:value-of select="$newline"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

このスタイルシートでは、createJPEG() 関数を利用できる場合、その関数を呼び出して、すべてのお気に入りのアルバムのタイトル用に JPEG ファイルを作成します。関数が利用できない場合、タイトルを出力ストリームに書き込みます。createJPEG() 関数が利用できる場合の結果は次のとおりです。


See the file album1.jpg to see the title of album #1
See the file album2.jpg to see the title of album #2
See the file album3.jpg to see the title of album #3
See the file album4.jpg to see the title of album #4
See the file album5.jpg to see the title of album #5
See the file album6.jpg to see the title of album #6
See the file album7.jpg to see the title of album #7
See the file album8.jpg to see the title of album #8

すべてのアルバムタイトル (<listitem> 要素のテキスト) は JPEG グラフィックに変換されます。この例では、ファイル album8.jpg図 C-3 のようになります。

8 番目の <listitem> 要素用に生成されたグラフィック

ファイル JPEGWriter.class を削除した場合は、代わりに次のような結果となります。.class ファイルがない場合、関数は利用できません。


1. A Love Supreme
2. Beat Crazy
3. Here Come the Warm Jets
4. Kind of Blue
5. London Calling
6. Remain in Light
7. The Joshua Tree
8. The Indestructible Beat of Soweto