【问题标题】:Parse epub v3 TOC.xhtml解析 epub v3 TOC.xhtml
【发布时间】:2013-04-02 21:09:22
【问题描述】:

我想用 xslt 解析 epub v3 文件的 TOC.xhtml。 到目前为止,在我的 xsl 文件中,我有以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:epub="http://www.idpf.org/2007/ops">
    <xsl:template match="/">
        <div id="tocItems">      
            <xsl:apply-templates select="/epub:html/epub:body/epub:nav/epub:ol/epub:li" />
        </div> 
    </xsl:template>

    <xsl:template match="epub:li">
        <br />
        hello
        <button class="option" onclick="parent.loadHREF(this)">                     
            <xsl:attribute name="id">
                <xsl:value-of select="epub:a/@href" />
            </xsl:attribute>
            <xsl:attribute name="name">
                <xsl:value-of select='position()' />
            </xsl:attribute>
            <xsl:value-of select="epub:a" />
        </button>
    </xsl:template>

</xsl:stylesheet>

不幸的是,这并没有给出任何输出。 这是一个典型的TOC.xhtml文件,希望有人能帮忙。

 <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="tableofcontentsV3.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
  <head>
    <meta http-equiv="default-style" content="text/html; charset=utf-8"/>
    <title>Contents</title>
    <link rel="stylesheet" href="css/famouspaintings.css" type="text/css"/>
  </head>
  <body>

<nav epub:type="toc"><h2>Contents</h2>
  <ol epub:type="list"><li><a href="s001-Cover-01.xhtml">Cover</a></li>
<li><a href="s002-BookTitlePage-01.xhtml">Famous Paintings</a></li>
<li><a href="s003-Copyright-01.xhtml">Copyright</a></li>
<li><a href="s004-Section-001.xhtml">Explore</a></li>
<li><a href="s005-Section-002.xhtml">Famous Paintings</a></li>
<li><a href="s018-Section-009.xhtml">Colophon</a></li>
</ol></nav></body>
</html>

【问题讨论】:

    标签: xml xslt tableofcontents epub3


    【解决方案1】:

    您尝试匹配的元素不在 epub 命名空间中;它们位于 xhtml 命名空间中。尝试在 xsl:stylesheet 中为 xhtml 命名空间添加前缀并更改路径中的前缀:

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:epub="http://www.idpf.org/2007/ops">
        <xsl:template match="/">
            <div id="tocItems">      
                <xsl:apply-templates select="/xhtml:html/xhtml:body/xhtml:nav/xhtml:ol/xhtml:li" />
            </div> 
        </xsl:template>
    
        <xsl:template match="xhtml:li">
            <br />
            hello
            <button class="option" onclick="parent.loadHREF(this)">                     
                <xsl:attribute name="id">
                    <xsl:value-of select="xhtml:a/@href" />
                </xsl:attribute>
                <xsl:attribute name="name">
                    <xsl:value-of select='position()' />
                </xsl:attribute>
                <xsl:value-of select="xhtml:a" />
            </button>
        </xsl:template>
    
    </xsl:stylesheet>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多