[xquery-talk] novice questions mailing list

Geert Josten geert.josten at dayon.nl
Fri Dec 13 13:42:03 PST 2013


David is right that XSLT questions are better off on the xsl list, but I am
going to give a few hints anyhow. XSLT processing normally starts at
template match="/", which matches the document node of your input. You
likely want to write the outline of your HTML page in such a template. You
also need to be aware that there are built-in templates which are selected
if none of your own templates match. Their default behavior is more or less
to copy character data. If you want to suppress any character data other
than the author names, the simplest way is to change your current template's
match attribute to match="/", and add select=".//author" to your current
xsl:apply-templates statement..

Good luck,
Geert

> -----Oorspronkelijk bericht-----
> Van: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com]
> Namens e-letter
> Verzonden: vrijdag 13 december 2013 0:38
> Aan: David Lee
> CC: talk at x-query.com
> Onderwerp: Re: [xquery-talk] novice questions mailing list
>
> On 12/12/2013, David Lee <dlee at calldei.com> wrote:
> > I think you will find this list very accommodating to basic questions.
> > All of us on this list knew nothing about xpath at one point.
> >
> > I recommend with any question you supply sample XML and good
> description of
> > what you are trying to accomplish along with any xpath or xquery code
> > you
> > have attempted
> > and what it produced and why you belive it is the wrong result.
> >
>
> Here goes:
>
> 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="1.0" encoding="utf-8"?>
> <!-- Edited by XMLSpy®, taken from http://www.w3schools.com-->
> <?xml-stylesheet type='text/xsl" href="xstylesheetexample.xslt" ?>
> <bookstore>
> 	<book category="COOKING">
> 		<title lang="en">Everyday Italian</title>
> 		<author>Giada De Laurentiis</author>
> 		<year>2005</year>
> 		<price>30.00</price>
> 	</book>
> 	<book category="CHILDREN">
> 		<title lang="en">Harry Potter</title>
> 		<author>J K. Rowling</author>
> 		<year>2005</year>
> 		<price>29.99</price>
> 	</book>
> 	<book category="WEB">
> 		<title lang="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="WEB">
> 		<title lang="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="1.1"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:import href="xqueryexampledata.xml"/>
> 	<xsl:output
> 		method="xml"
> 		doctype-public="-//W3C//DTD XHTML Basic 1.1//EN"
> 		doctype-system="http://www.w3.org/TR/xhtml-basic/xhtml-
> basic11.dtd"
> 		encoding="utf-8"
> 		indent="no"
> 		omit-xml-declaration="yes"
> 		media-type="text/xml"
> 		standalone="yes"
> 		version="1.1"
> 		/>
> 	<xsl:template
> 		match="author">
> 		<html xmlns='http://www.w3.org/1999/xhtml' lang='en'
> xml:lang='en'>
> 			<head>
> 				<meta
> 					name='note' content='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="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>Giada De Laurentiis</p></body></html>
> 		2005
> 		30.00
>
>
> 		Harry Potter
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>J K. Rowling</p></body></html>
> 		2005
> 		29.99
>
>
> 		XQuery Kick Start
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>James McGovern</p></body></html>
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>Per Bothner</p></body></html>
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>Kurt Cagle</p></body></html>
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>James Linn</p></body></html>
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="note" /><title>Test output web
> page</title></head><body><p>Vaidyanathan
> Nagarajan</p></body></html>
> 		2003
> 		49.99
>
>
> 		Learning XML
> 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
> lang="en"><head><meta content="xhtml document created by xml
> transformation" name="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
> correctly!
>
> 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='http://www.w3.org/1999/xhtml' lang='en'
> xml:lang='en'>
> 		<head>
> 			<meta
> 				content="xhtml document created by xml
> transformation" name="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>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list