XSLT函数——element-available()

      element-available函数用来判断某个XSLT元素是否能够被处理器解析。参数string用来指定XSLT元素的名称。只有可作为元素<xsl:template>的子元素出现的XSLT元素才会返回true。 这些元素如下:<xsl:apply-import>,<xsl:apply-templates>,<xsl:attribute>,<xsl:call-template>,<xsl:choose>,<xsl:comment>,<xsl:copt>,<xsl:copy-of>,<xsl:element>,<xsl:fallback>,<xsl:for-each>,<xsl:if>,<xsl:message>,<xsl:number>,<xsl:processing-instruction>,<xsl:text>,<xsl:value-of>,<xsl:variable>.

      语法:element-available(string)

      参数:string字符串,必需

     返回值:布尔型

示例:

xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
    <books/>

xslt:

  1. <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="html" version="1.0" encoding="gb2312" indent="yes"/>    
        <xsl:template match="/">
           <xsl:choose>
                <xsl:when test="element-available('xsl:if')">
                   <xsl:text>&lt;xsl:if&gt;可用</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                   <xsl:text>&lt;xsl:if&gt;不可用</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="element-available('xsl:tpye')">
                   <xsl:text>&lt;xsl:type&gt;可用</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                   <xsl:text>&lt;xsl:type&gt;不可用</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>

结果为:

  1. <xsl:if>可用<xsl:type>不可用

posted @ 2010-01-17 02:00  Asharp  阅读(608)  评论(0编辑  收藏  举报