Name

[2.0] unparsed-text-available()

Given a URI, returns true if that document is available, false otherwise. This function allows you to check the existence and availability of a document before you attempt to open it with unparsed-text(). If you attempt to open a document that is unavailable, the XSLT processor raises a fatal error.

Syntax

xs:boolean unparsed-text-available(xs:string)
xs:boolean unparsed-text-available(xs:string, xs:string)

Inputs

An xs:string specifying the URI of the requested document. An optional second string specifies the document’s encoding.

Output

true if the document is unavailable; false otherwise.

Defined in

XSLT 2.0 section 16.2, “Reading Text Files.”

Example

Here’s a short stylesheet that checks to see whether three different files are available:

<?xml version="1.0"?>
<!-- unparsed-text-available.xsl -->
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="text"/>

  <xsl:template match="/">

    <xsl:text>&#xA;Here are some tests of the </xsl:text>
    <xsl:text>unparsed-text-available() function:</xsl:text>

    <xsl:text>&#xA;&#xA;  unparsed-text-available</xsl:text>
    <xsl:text>('header.html') = </xsl:text>
    <xsl:value-of 
      select="unparsed-text-available('header.html')"/>

    <xsl:text>&#xA;&#xA;  unparsed-text-available</xsl:text>
    <xsl:text>('disclaimer.html') = </xsl:text>
    <xsl:value-of 
      select="unparsed-text-available('disclaimer.html')"/> <xsl:text>&#xA;&#xA; unparsed-text-available</xsl:text> <xsl:text>('footer.html') = </xsl:text> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.