XSLT apply-template does not show multiple of same tag



I'm using XSLT stylesheet to render a simple XML file of the text of Alice in Wonderland into HTML.



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Alice.xsl"?>


<book>
<title>Alice's Adventures in Wonderland</title>

<text>
<chapter>
<chapter_heading>Chapter I. Down the Rabbit-Hole</chapter_heading>

<p>Alice was beginning to get very tired of sitting by her sister on the
bank, and of having nothing to do: once or twice she had peeped into the
book her sister was reading, but it had no pictures or conversations in
it, 'and what is the use of a book,' thought Alice 'without pictures or
conversations?'</p>

<p>So she was considering in her own mind (as well as she could, for the
hot day made her feel very sleepy and stupid), whether the pleasure
of making a daisy-chain would be worth the trouble of getting up and
picking the daisies, when suddenly a White Rabbit with pink eyes ran
close by her.</p>
</chapter>

</text>
</book>


Simple stuff. And we're trying to output just the Title of the Chapter and the paragraphs into an tag in HTML using this code:



<?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="http://ift.tt/tCZ8VR" -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="html" encoding="UTF-8"/>

<xsl:template match="/">
<html xmlns="http://ift.tt/lH0Osb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

</head>

<body>

<article>
<xsl:apply-templates/>
</article>

</body>


</html>
</xsl:template>

<xsl:template match="title"/>

<xsl:template match="chapter">
<h3>
<xsl:apply-templates select="chapter_heading"/>
</h3>
<div class="paragraph">
<xsl:apply-templates select="p"/>
</div>
</xsl:template>


</xsl:stylesheet>


But once the XML file is opened in a browser, all of the separate 'p' tags in the XML are just grouped together into one large 'div' in the HTML.


Our group is obviously very new to XSL, but as far as we've been able to research, we don't tell why this isn't working smoothly. Any help would be appreciated!


No comments:

Post a Comment