2016-02-11 83 views
0

我感兴趣的是使用xml和xslt作为排版工作流程的一部分,通过使用xslt来转换我的标记系统以匹配乳胶格式。有两个解决方案,我创建了一个小的XML文档,其中包含了所有我需要在第一个项目中使用的所有结构元素。来自XSLT转换的幻像输出

这个过程仍然是非常初步的,到目前为止,我一直在确保我可以找到和识别我的XML的元素。然而,我得到了一些让我难以置信的奇特产物。

我的转换似乎是返回的信息,只是没有被要求,连同信息是。奇怪的是,我在之前的测试中成功地请求了无关信息。有谁知道为什么我的输出中包含书目信息?

谢谢!

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> 

输出:

This is Title of The Book 

    \chapter{Chapter 1} 



What If There Was Another Book? 
+0

为什么不公开可用的东西就已经这是否... https://sourceforge.net/projects/db2latex/ –

回答

3

有内置的模板,确保处理完成,请参阅https://www.w3.org/TR/xslt#built-in-rule。没有他们,你的模板将永远不会被处理。所以你要么确保你有

<xsl:template match="/"> 
    <xsl:apply-templates select="//chapter"/> 
</xsl:template> 

只处理元素(S)要处理,或者你需要为文本节点确保模板不输出任何东西:

<xsl:template match="text()"/>