Reputation: 97
I'm interested in using xml and xslt as part of a typesetting work flow, by using xslt to translate my system of tags to match a latex format. Two work out the kinks, I created a small xml document that includes all all the structural elements that I'll need to work with in my first project.
This process is still very preliminary and so far I've just been making sure that I can find and identify elements of my xml. However, I've gotten some peculiar outputs that have me stumped.
My transformation seems to be returning information that simply isn't being asked for, along with the information that is. What's stranger is that I requested the extraneous information successfully in a previous test. Does anyone know why the booktitle information is being included in my output?
Thanks!
XML:
<document>
<book>
<booktitle>This is Title of The Book</booktitle>
<chapter>
<chaptertitle>Chapter 1</chaptertitle>
<paragraph>It only has one chapter, and very few words, because it is only a test.</paragraph>
<paragraph>I've made two paragraphs, though. This paragraph has an endnote.<endnote>It is marked by an arabic numeral, and can be found at the end of the document</endnote></paragraph>
<section>
<sectiontitle>Brevity not withstanding...</sectiontitle>
<paragraph>This book has a section, so that I can check the extent of the structure. Here we can find a margin note.<marginnote>They appear next to the body text, in the margin of the page.</marginnote></paragraph>
<paragraph>Here's one last paragraph to test another feature. <verse>Here is some verse.// It is terse.<attribution>The Author</attribution></verse></paragraph>
</section>
</chapter>
</book>
<book>
<booktitle>What If There Was Another Book?</booktitle>
</book>
</document>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="chapter">
\chapter{<xsl:value-of select="chaptertitle"/>}
</xsl:template>
</xsl:stylesheet>
Output:
This is Title of The Book
\chapter{Chapter 1}
What If There Was Another Book?
Upvotes: 0
Views: 60
Reputation: 167401
There are built-in templates that make sure processing is done, see https://www.w3.org/TR/xslt#built-in-rule. Without them your template would never be processed. So you either need to make sure you have e.g.
<xsl:template match="/">
<xsl:apply-templates select="//chapter"/>
</xsl:template>
to only process the element(s) you want to process or you need to make sure templates for text nodes don't output anything:
<xsl:template match="text()"/>
Upvotes: 3