Readers,
This post was mistakenly posted in an x-query mailing list, where it
was suggested to post here. For any help that can be provided, thanks
in advance.
The objective is to learn how to select nodes in an xml file and use
xpath and xslt to select nodes of interest and display in a new file.
An xml file was created:
<?xml version=3D"1.0" encoding=3D"utf-8"?>
<!-- Edited by XMLSpy=C2=AE, taken from http://www.w3schools.com-->
<?xml-stylesheet type=3D'text/xsl" href=3D"xstylesheetexample.xslt" ?>
<bookstore>
<book category=3D"COOKING">
<title lang=3D"en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category=3D"CHILDREN">
<title lang=3D"en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category=3D"WEB">
<title lang=3D"en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category=3D"WEB">
<title lang=3D"en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
An xml stylesheet was created:
<xsl:stylesheet version=3D"1.1"
xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform">
<xsl:import href=3D"xqueryexampledata.xml"/>
<xsl:output
method=3D"xml"
doctype-public=3D"-//W3C//DTD XHTML Basic 1.1//EN"
doctype-system=3D"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"
encoding=3D"utf-8"
indent=3D"no"
omit-xml-declaration=3D"yes"
media-type=3D"text/xml"
standalone=3D"yes"
version=3D"1.1"
/>
<xsl:template
match=3D"author">
<html xmlns=3D'http://www.w3.org/1999/xhtml' lang=3D'en'
xml:lang=3D'en'>
<head>
<meta
name=3D'note' content=3D'xhtml
document created by xml transformation' />
<title>Test output web page</title>
</head>
<body>
<p>
<xsl:apply-templates/>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The text editor 'jedit' is used with xml plugins xslt, xquery, xml.
The xslt transformer plugin is used to select the above xml file and
xslt file for subsequent transformation, to create an output xhtml
file.
The result of this transformation is the creation of a new xhtml file
(as stated in the stylesheet above):
Everyday Italian
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>Giada De Laurentiis</p></body></html>
2005
30.00
Harry Potter
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>J K. Rowling</p></body></html>
2005
29.99
XQuery Kick Start
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>James McGovern</p></body></html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>Per Bothner</p></body></html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>Kurt Cagle</p></body></html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>James Linn</p></body></html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>Vaidyanathan Nagarajan</p></body></html>
2003
49.99
Learning XML
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D=
"en"
lang=3D"en"><head><meta content=3D"xhtml document created by xml
transformation" name=3D"note" /><title>Test output web
page</title></head><body><p>Erik T. Ray</p></body></html>
2003
39.95
Clearly, there's a lot to learn in specifying the transformation correct=
ly!
The ideal output is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<html xmlns=3D'http://www.w3.org/1999/xhtml' lang=3D'en' xml:lan=
g=3D'en'>
<head>
<meta
content=3D"xhtml document created by
xml transformation" name=3D"note"
/>
<title>Test output web page</title>
</head>
<body>
<p>Giada De Laurentiis</p>
<p>J K. Rowling</p>
<p>James McGovern</p>
<p>Per Bothner</p>
<p>Kurt Cagle</p>
<p>James Linn</p>
<p>Vaidyanathan Nagarajan</p>
<p>Erik T. Ray</p>
</body>
</html>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--