【发布时间】:2014-02-22 07:10:33
【问题描述】:
我正在使用 xml 和 xslt。我有以下 xml
<book>
<book-part book-part-type="chapter" book-part-number="1" id="PT-161_ch_1">
<book-meta>
<book-title-group>
<book-title>Software-Hardware Integration in Automotive Product Development</book-title>
</book-title-group>
</book-meta>
<book-part-meta>
<title-group>
<title>
<bold>2008-21-0043</bold>
</title>
</title-group>
</book-part-meta>
<body>
<sec id="ch1.1">
<title>INTRODUCTION</title>
<p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market. New system architectures are providing the performance and memory capability necessary to keep up with the hardware performance and software growth required by the automotive market trends. All of this technology growth implies a higher product cost and increased engineering effort required to develop these new products.</p>
</sec>
</body>
我有以下 XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
<xsl:template match="book-part">
<html>
<head>
</head>
<body>
<xsl:for-each select="book-meta">
<p>
<b>
<xsl:value-of select="book-title-group/book-title"/>
</b>
</p>
</xsl:for-each>
<xsl:for-each select="book-part-meta">
<p>
<b>
<xsl:value-of select="title-group/title"/>
</b>
</p>
</xsl:for-each>
<xsl:for-each select="body/sec">
<p>
<ol>
<li>
<b>
<div>
<xsl:value-of select="title"/>
</div>
</b>
</li>
</ol>
<xsl:for-each select="p">
<xsl:value-of select="text()"/>
</xsl:for-each>
</p>
<xsl:for-each select="sec">
<p>
<ol>
<li>
<b>
<div>
<xsl:value-of select="title"/>
</div>
</b>
</li>
</ol>
<xsl:value-of select="p"/>
</p>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="text()[parent::xref]"/>
</xsl:stylesheet>
我必须将此 XML 转换为 EPub。为了将其转换为 Epub,我首先使用 XSLCompiledTransform 将其转换为 html,然后将 html 转换为 xhtml,然后使用 Spire.doc,此 xhtml 正在转换为 Epub。
但是在将 xhtml 转换为 Epub Spire.doc 时出现以下错误
命名空间'http://www.w3.org/1999/xhtml'中的元素'body'不能 包含文本。预期的可能元素列表: 'http://www.w3.org/1999/xhtml:p h1 h2 h3 h4 h5 h6 div ul ol dl pre hr 块引用...
我没有确切知道应该在 xslt 中进行哪些更改才能解析“text()”。
【问题讨论】:
-
您显示的 XSLT 似乎与您的 XML 不匹配。 XSLT 正在寻找匹配 XML 中不存在的“书本部分”。理想情况下,问题需要显示用于生成“Spire.doc”输入的 XML 和 XSLT。谢谢!
-
此外,您显示的 XML 输入不可能得到您显示的错误。在您转换的实际 XML 输入中,必须有文本内容作为
body元素的子元素(这是禁止的)。 -
@Tim C 我已经更新了我的确切 XML,现在请解释我面临的问题的原因。
-
不过,您更新的 XML 输入没有意义并且格式不正确。
标签: c# xml xslt xslt-1.0 spire.doc