Name

[2.0] unparsed-text()

Given a URI, returns the unparsed text of the resources identified by that URI.

Syntax

xs:string unparsed-text($href as xs:string)
xs:string unparsed-text($href as xs:string, $encoding as xs:string)

Inputs

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

Output

An xs:string that contains the unparsed text of the URI.

Defined in

XSLT 2.0 section 16.2, “Reading Text Files.”

Example

In this example, we’ll generate an HTML page. Part of the page is a standard header and footer; those will be inserted into the document as unparsed text. If we use the collection(), doc(), or document() functions, the data we read would have to be well-formed XML. Using unparsed-text() instead, we can read documents that aren’t necessarily well-formed (most HTML documents, for example) and use them.

We’ll use our document of chocolate bar sales as the XML input document:

<?xml version="1.0" encoding="utf-8"?>
<!-- chocolate.xml -->
<report month="8" year="2006">
  <title>Chocolate bar sales</title>
  <brand>
    <name>Lindt</name>
    <units>27408</units>
  </brand>
  <brand>
    <name>Callebaut</name>
    <units>8203</units>
  </brand>
  <brand>
    <name>Valrhona</name>
    <units>22101</units>
  </brand>
  <brand>
    <name>Perugina</name>
    <units>14336</units>
  </brand>
  <brand>
    <name>Ghirardelli</name>
    <units>19268</units>
  </brand>
</report>

We’ll generate an HTML report from this document. Our stylesheet uses unparsed-text() to import an HTML header and footer: ...

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.