X hits on this document

464 views

0 shares

1 downloads

0 comments

42 / 142

Transforming XML with XSLT

<xsl:template match="/content">

<!-- output the contents of content and a line-feed --> <xsl:value-of select='.'/> <xsl:text>&#xa;</xsl:text>

<!-- clean up --> </xsl:template>

</xsl:stylesheet>

This is what the stylesheet does:

  • 1.

    Defines itself as an XML file

  • 2.

    Defines itself as an XSLT stylesheet

  • 3.

    Defines the output format as plain text

  • 4.

    Looks for the root element, content.

  • 5.

    Outputs the value of the root element

  • 6.

    Outputs a line-feed character

  • 7.

    Closes the opened elements

Give the stylesheet a try:

  • 1.

    Opening a command prompt.

  • 2.

    Change directories to the getting-started directory of the workshop's directory.

  • 3.

    Transform the hello-world.xml file: xsltproc hello-world.xsl hello-world.xml .

Exercise - XML to text

In a previous exercise you created a letter (ala.xml) using our own mark up. We will now use XSLT to transform it to plain text file.

As review, open ala.xml. Not too complicated.

To create a plain text version of this file, we will use the following stylesheet:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- plain o' text --> <xsl:output method='text'/>

<!-- let's get started -->

34

Document info
Document views464
Page views470
Page last viewedFri Dec 09 14:30:37 UTC 2016
Pages142
Paragraphs3126
Words34660

Comments