spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / authoring / languages / xml / insidexslt / chap2 / 5 To page 1To page 2To page 3current page
[previous]

Inside XSLT

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Output Method: Text

The text output method is not just for creating plain text; it's used for any non-XML, non-HTML text-based format. For example, you can use it to create Rich Text Format (RTF) documents. Rich Text Format uses embedded text-based codes to specify the format of documents, and you can place those text-based codes in documents yourself if you use the text output method.

Here's an example stylesheet (that you'll see in Chapter 6) that converts planets.xml into planets.rtf:

Listing 2.6: RTF Stylesheet

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:strip-space elements="*"/>
<xsl:template match="/PLANETS">{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0
Courier New;}}
\viewkind4\uc1\pard\lang1033\b\f0\fs36 The Planets Table\par
\b0\fs20
Name\tab Mass\tab Rad.\tab Day\par
<xsl:apply-templates/>
\par
}</xsl:template>
<xsl:template match="PLANET">
<xsl:value-of select="NAME"/>
\tab
<xsl:value-of select="MASS"/>
\tab
<xsl:value-of select="RADIUS"/>
\tab
<xsl:value-of select="DAY"/>
\tab
\par
</xsl:template>
</xsl:stylesheet>

You can see the resulting RTF document, planets.rtf, in Figure 2.3 in Microsoft Word 2000.

Note that I've set the output method to text with <xsl:output method="text"/>:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/PLANETS">{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
\viewkind4\uc1\pard\lang1033\b\f0\fs36 The Planets Table\par
        .
        .
        .

You might also note that I've started the RTF codes immediately after the <xsl:template> element. I've done that because RTF documents must start with RTF codes from the very beginning; if I had begun inserting RTF codes on the next line, like this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/PLANETS">
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
\viewkind4\uc1\pard\lang1033\b\f0\fs36 The Planets Table\par
        .
        .
        .

then the RTF output file would have started with a newline character, which would throw off the RTF application like Microsoft Word. You'll learn more on RTF and other formats in Chapter 6.

Figure 2.3. Planets.rtf in Microsoft Word.
Figure 2.3 Planets.rtf in Microsoft Word.


home / authoring / languages / xml / insidexslt / chap2 / 5 To page 1To page 2To page 3current page
[previous]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: October 11, 2001
Revised: October 11, 2001


URL: http://webreference.com/authoring/languages/xml/insidexslt/chap2/5/4.html