XML Tutorials - Herong's Tutorial Examples - v5.25, by Herong Yang
XSLT Transformation and HTML View
This section provides a tutorial example on how to perform XSLT (Extensible Stylesheet Language Transformations) in XML Notepad 2007.
XML Notepad 2007 can not be used to apply generic XSLT (Extensible Stylesheet Language Transformations). But it can apply special XSLT transformation that generates HTML documents.
The example below shows you how XML Notepad 2007 can be used apply an XSLT transformation as HTML viewer for RSS documents.
1. Assuming we have the following RSS document, rss.xml, with rss-viewer.xsl specified in the document:
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="rss-viewer.xsl"?> <rss version="2.0"> <channel> <generator>NFE/1.0</generator> <title>Science - Google News</title> <link>http://news.google.com/news?pz=1&ned=us&...</link> <language>en</language> <webMaster>news-feedback@google.com</webMaster> <copyright>&copy;2013 Google</copyright> <pubDate>Sun, 1 Mar 2013 22:22:30 GMT</pubDate> <lastBuildDate>Sun, 1 Mar 2013 22:22:30 GMT</lastBuildDate> <image> <title>Science - Google News</title> <url>http://www.gstatic.com/news-static/.../news.gif</url> <link>http://news.google.com/news?pz=1&ned=us&...</link> </image> <item> <title>Privately Financed Spaceship Roars Closer to Space - New York Times</title> <link>http://news.google.com/news/url?sa=t&fd=R...</link> <guid isPermaLink="false">tag:...:cluster=52778136490111</guid> <category>Science</category> <pubDate>Sun, 1 Mar 2013 21:27:11 GMT</pubDate> <description>For the more than 500 space...</description> </item> <item> <title>NASA eyes monster hurricane on Saturn - Fox News</title> <link>http://news.google.com/news/url?sa=t&fd=R...</link> <guid isPermaLink="false">tag:...:cluster=52778138308485</guid> <category>Science</category> <pubDate>Sun, 1 Mar 2013 11:40:58 GMT</pubDate> <description>Spectacular new images from a NASA...</description> </item> <item> <title>Fossil Discovery Traces Dinosaur Family Line to Africa - Headlines & Global News</title> <link>http://news.google.com/news/url?sa=t&fd=R...</link> <guid isPermaLink="false">tag:...:cluster=52778138328576</guid> <category>Science</category> <pubDate>Sun, 1 Mar 2013 13:21:53 GMT</pubDate> <description>The discovery of fossils dating...</description> </item> <description>Google News</description> </channel> </rss>
2. Assuming we also have the following RSS to HTML XSLT transformation template, rss-viewer.xsl:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- rss-viewer.xsl - Copyright (c) 2002-2018 HerongYang.com. All Rights Reserved. --> <xsl:template match='/rss'> <html><body> <b><xsl:value-of select='channel/title'/></b> - <xsl:value-of select='channel/description'/> - <i><xsl:value-of select='channel/pubDate'/></i> <ul><xsl:apply-templates select='channel/item'/></ul> </body></html> </xsl:template> <xsl:template match='item'> <li> <b><xsl:value-of select='title'/></b> - <xsl:value-of select='description'/> - <i><xsl:value-of select='pubDate'/></i> </li> </xsl:template> </xsl:stylesheet>
3. Open rss.xml in XML Notepad 2007 and click the "XSL Output" tab. The XSLT template, rss-viewer.xsl, will be applied automatically. You see the transformed HTML document be rendered and displayed:
4. Right-mouse click on HTML display area, and select "View source". You see HTML source code showing up in Notepad editor:
<html> <body><b>Science - Google News</b> - Google News - <i>Sun, 1 Mar 2013 22:22:30 GMT</i><ul> <li><b>Privately Financed Spaceship Roars Closer to...</b> - For the more than 500 space tourists who have signed up for a trip... <i>Sun, 1 Mar 2013 21:27:11 GMT</i></li> <li><b>NASA eyes monster hurricane on Saturn - Fox News</b> - Spectacular new images from a NASA spacecraft orbiting Saturn have... <i>Sun, 1 Mar 2013 11:40:58 GMT</i></li> <li><b>Fossil Discovery Traces Dinosaur Family Line to...</b> - The discovery of fossils dating back to about 10 million years... <i>Sun, 1 Mar 2013 13:21:53 GMT</i></li> </ul> </body> </html>
Of course, if the XSLT file is not provided in the XML document, you can specify it through the "XSLT location" field.
Table of Contents
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
SAX (Simple API for XML) Programming Interface
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
XSLT Elements as Programming Statements
Control and Generate XML Element in the Result
PHP Extensions for XML Manipulation
Processing XML with Python Scripts
Downloading and Installing XML Notepad
Creating XML Documents in Tree View
Viewing XML Documents in Source Code
Converting XML in Pretty Print Format
►XSLT Transformation and HTML View
XML Tools Plugin for Notepad++
XML Plugin Packages for Atom Editor