توابع element-available() XSLT

تعریف و استفاده

تابع element-available() یک مقدار بولین بازمی‌گرداند که نشان می‌دهد پردازش‌کننده XSLT از عناصر مشخص‌شده پشتیبانی می‌کند یا خیر.

این تابع فقط برای تست عناصر در بدنه پترن استفاده می‌شود. این عناصر عبارتند از:

  • xsl:apply-imports
  • xsl:apply-templates
  • xsl:attributes
  • xsl:call-template
  • xsl:choose
  • xsl:comment
  • xsl:copy
  • 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

دستور زبان

boolean element-available(string)

پارامتر

پارامتر توضیح
string ضروری است. تعیین عناصر برای تست.

مثال

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:choose>
<xsl:when test="element-available('xsl:comment')">
<p>xsl:comment پشتیبانی می‌شود.</p>
</xsl:when>
<xsl:otherwise>
<p>xsl:comment پشتیبانی نمی‌شود.</p>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="element-available('xsl:delete')">
<p>xsl:delete پشتیبانی می‌شود.</p>
</xsl:when>
<xsl:otherwise>
<p>پشتیبانی از xsl:delete وجود ندارد.</p>
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

فایل XSL را مشاهده کنید،نتیجه را مشاهده کنید