O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required