توابع 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 را مشاهده کنید,نتیجه را مشاهده کنید.