- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将一些关于信息技术的文章从 XHTML 或 HTML 格式转换为 Docbook 格式。然后我需要将 Docbook 格式转换为 pdf。但是我对第一句话有疑问。我现在不知道如何将 XHTML/HTML 转换为 Docbook。谢谢
最佳答案
如今,您可以使用 pandoc并做:
pandoc -f html -t docbook input.html
或者:
我终于找到了将 XHTML 转换为 DocBook 的 XSLT。 Internet WayBackMachine 有一个 backup在 wiki.docbook.org 上找不到的 HTML2DocBook 维基页面。因此,万一 waybackmachine 停止工作或其他原因,给你。
请注意,输出使用桥头而不是节/标题。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:saxon="http://icl.com/saxon"
exclude-result-prefixes="xsl fo html saxon">
<xsl:output method="xml" indent="no"/>
<xsl:param name="filename"></xsl:param>
<xsl:param name="prefix">wb</xsl:param>
<xsl:param name="graphics_location">file:///epicuser/AISolutions/graphics/AIWorkbench/</xsl:param>
<!-- Main block-level conversions -->
<xsl:template match="html:html">
<xsl:apply-templates select="html:body"/>
</xsl:template>
<!-- This template converts each HTML file encountered into a DocBook
section. For a title, it selects the first h1 element -->
<xsl:template match="html:body">
<section>
<xsl:if test="$filename != ''">
<xsl:attribute name="id">
<xsl:value-of select="$prefix"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="translate($filename,' ()','__')"/>
</xsl:attribute>
</xsl:if>
<title>
<xsl:value-of select=".//html:h1[1]
|.//html:h2[1]
|.//html:h3[1]"/>
</title>
<xsl:apply-templates select="*"/>
</section>
</xsl:template>
<!-- This template matches on all HTML header items and makes them into
bridgeheads. It attempts to assign an ID to each bridgehead by looking
for a named anchor as a child of the header or as the immediate preceding
or following sibling -->
<xsl:template match="html:h1
|html:h2
|html:h3
|html:h4
|html:h5
|html:h6">
<bridgehead>
<xsl:choose>
<xsl:when test="count(html:a/@name)">
<xsl:attribute name="id">
<xsl:value-of select="html:a/@name"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="preceding-sibling::* = preceding-sibling::html:a[@name != '']">
<xsl:attribute name="id">
<xsl:value-of select="concat($prefix,preceding-sibling::html:a[1]/@name)"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="following-sibling::* = following-sibling::html:a[@name != '']">
<xsl:attribute name="id">
<xsl:value-of select="concat($prefix,following-sibling::html:a[1]/@name)"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:apply-templates/>
</bridgehead>
</xsl:template>
<!-- These templates perform one-to-one conversions of HTML elements into
DocBook elements -->
<xsl:template match="html:p">
<!-- if the paragraph has no text (perhaps only a child <img>), don't
make it a para -->
<xsl:choose>
<xsl:when test="normalize-space(.) = ''">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<para>
<xsl:apply-templates/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="html:pre">
<programlisting>
<xsl:apply-templates/>
</programlisting>
</xsl:template>
<!-- Hyperlinks -->
<xsl:template match="html:a[contains(@href,'http://')]" priority="1.5">
<ulink>
<xsl:attribute name="url">
<xsl:value-of select="normalize-space(@href)"/>
</xsl:attribute>
<xsl:apply-templates/>
</ulink>
</xsl:template>
<xsl:template match="html:a[contains(@href,'#')]" priority="0.6">
<xref>
<xsl:attribute name="linkend">
<xsl:call-template name="make_id">
<xsl:with-param name="string" select="substring-after(@href,'#')"/>
</xsl:call-template>
</xsl:attribute>
</xref>
</xsl:template>
<xsl:template match="html:a[@href != '']">
<xref>
<xsl:attribute name="linkend">
<xsl:value-of select="$prefix"/>
<xsl:text>_</xsl:text>
<xsl:call-template name="make_id">
<xsl:with-param name="string" select="@href"/>
</xsl:call-template>
</xsl:attribute>
</xref>
</xsl:template>
<!-- Need to come up with good template for converting filenames into ID's -->
<xsl:template name="make_id">
<xsl:param name="string" select="''"/>
<xsl:variable name="fixedname">
<xsl:call-template name="get_filename">
<xsl:with-param name="path" select="translate($string,' \()','_/_')"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($fixedname,'.htm')">
<xsl:value-of select="substring-before($fixedname,'.htm')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$fixedname"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="string.subst">
<xsl:param name="string" select="''"/>
<xsl:param name="substitute" select="''"/>
<xsl:param name="with" select="''"/>
<xsl:choose>
<xsl:when test="contains($string,$substitute)">
<xsl:variable name="pre" select="substring-before($string,$substitute)"/>
<xsl:variable name="post" select="substring-after($string,$substitute)"/>
<xsl:call-template name="string.subst">
<xsl:with-param name="string" select="concat($pre,$with,$post)"/>
<xsl:with-param name="substitute" select="$substitute"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Images -->
<!-- Images and image maps -->
<xsl:template match="html:img">
<xsl:variable name="tag_name">
<xsl:choose>
<xsl:when test="boolean(parent::html:p) and
boolean(normalize-space(parent::html:p/text()))">
<xsl:text>inlinemediaobject</xsl:text>
</xsl:when>
<xsl:otherwise>mediaobject</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$tag_name}">
<imageobject>
<xsl:call-template name="process.image"/>
</imageobject>
</xsl:element>
</xsl:template>
<xsl:template name="process.image">
<imagedata>
<xsl:attribute name="fileref">
<xsl:call-template name="make_absolute">
<xsl:with-param name="filename" select="@src"/>
</xsl:call-template>
</xsl:attribute>
<xsl:if test="@height != ''">
<xsl:attribute name="depth">
<xsl:value-of select="@height"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@width != ''">
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
</xsl:if>
</imagedata>
</xsl:template>
<xsl:template name="make_absolute">
<xsl:param name="filename"/>
<xsl:variable name="name_only">
<xsl:call-template name="get_filename">
<xsl:with-param name="path" select="$filename"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$graphics_location"/><xsl:value-of select="$name_only"/>
</xsl:template>
<xsl:template match="html:ul[count(*) = 0]">
<xsl:message>Matched</xsl:message>
<blockquote>
<xsl:apply-templates/>
</blockquote>
</xsl:template>
<xsl:template name="get_filename">
<xsl:param name="path"/>
<xsl:choose>
<xsl:when test="contains($path,'/')">
<xsl:call-template name="get_filename">
<xsl:with-param name="path" select="substring-after($path,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- LIST ELEMENTS -->
<xsl:template match="html:ul">
<itemizedlist>
<xsl:apply-templates/>
</itemizedlist>
</xsl:template>
<xsl:template match="html:ol">
<orderedlist>
<xsl:apply-templates/>
</orderedlist>
</xsl:template>
<!-- This template makes a DocBook variablelist out of an HTML definition list -->
<xsl:template match="html:dl">
<variablelist>
<xsl:for-each select="html:dt">
<varlistentry>
<term>
<xsl:apply-templates/>
</term>
<listitem>
<xsl:apply-templates select="following-sibling::html:dd[1]"/>
</listitem>
</varlistentry>
</xsl:for-each>
</variablelist>
</xsl:template>
<xsl:template match="html:dd">
<xsl:choose>
<xsl:when test="boolean(html:p)">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<para>
<xsl:apply-templates/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="html:li">
<listitem>
<xsl:choose>
<xsl:when test="count(html:p) = 0">
<para>
<xsl:apply-templates/>
</para>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</listitem>
</xsl:template>
<xsl:template match="*">
<xsl:message>No template for <xsl:value-of select="name()"/>
</xsl:message>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@*">
<xsl:message>No template for <xsl:value-of select="name()"/>
</xsl:message>
<xsl:apply-templates/>
</xsl:template>
<!-- inline formatting -->
<xsl:template match="html:b">
<emphasis role="bold">
<xsl:apply-templates/>
</emphasis>
</xsl:template>
<xsl:template match="html:i">
<emphasis>
<xsl:apply-templates/>
</emphasis>
</xsl:template>
<xsl:template match="html:u">
<citetitle>
<xsl:apply-templates/>
</citetitle>
</xsl:template>
<!-- Ignored elements -->
<xsl:template match="html:hr"/>
<xsl:template match="html:h1[1]|html:h2[1]|html:h3[1]" priority="1"/>
<xsl:template match="html:br"/>
<xsl:template match="html:p[normalize-space(.) = '' and count(*) = 0]"/>
<xsl:template match="text()">
<xsl:choose>
<xsl:when test="normalize-space(.) = ''"></xsl:when>
<xsl:otherwise><xsl:copy/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Workbench Hacks -->
<xsl:template match="html:div[contains(@style,'margin-left: 2em')]">
<blockquote><para>
<xsl:apply-templates/></para>
</blockquote>
</xsl:template>
<xsl:template match="html:a[@href != ''
and not(boolean(ancestor::html:p|ancestor::html:li))]"
priority="1">
<para>
<xref>
<xsl:attribute name="linkend">
<xsl:value-of select="$prefix"/>
<xsl:text>_</xsl:text>
<xsl:call-template name="make_id">
<xsl:with-param name="string" select="@href"/>
</xsl:call-template>
</xsl:attribute>
</xref>
</para>
</xsl:template>
<xsl:template match="html:a[contains(@href,'#')
and not(boolean(ancestor::html:p|ancestor::html:li))]"
priority="1.1">
<para>
<xref>
<xsl:attribute name="linkend">
<xsl:value-of select="$prefix"/>
<xsl:text>_</xsl:text>
<xsl:call-template name="make_id">
<xsl:with-param name="string" select="substring-after(@href,'#')"/>
</xsl:call-template>
</xsl:attribute>
</xref>
</para>
</xsl:template>
<!-- Table conversion -->
<xsl:template match="html:table">
<!-- <xsl:variable name="column_count"
select="saxon:max(.//html:tr,saxon:expression('count(html:td)'))"/> -->
<xsl:variable name="column_count">
<xsl:call-template name="count_columns">
<xsl:with-param name="table" select="."/>
</xsl:call-template>
</xsl:variable>
<informaltable>
<tgroup>
<xsl:attribute name="cols">
<xsl:value-of select="$column_count"/>
</xsl:attribute>
<xsl:call-template name="generate-colspecs">
<xsl:with-param name="count" select="$column_count"/>
</xsl:call-template>
<thead>
<xsl:apply-templates select="html:tr[1]"/>
</thead>
<tbody>
<xsl:apply-templates select="html:tr[position() != 1]"/>
</tbody>
</tgroup>
</informaltable>
</xsl:template>
<xsl:template name="generate-colspecs">
<xsl:param name="count" select="0"/>
<xsl:param name="number" select="1"/>
<xsl:choose>
<xsl:when test="$count < $number"/>
<xsl:otherwise>
<colspec>
<xsl:attribute name="colnum">
<xsl:value-of select="$number"/>
</xsl:attribute>
<xsl:attribute name="colname">
<xsl:value-of select="concat('col',$number)"/>
</xsl:attribute>
</colspec>
<xsl:call-template name="generate-colspecs">
<xsl:with-param name="count" select="$count"/>
<xsl:with-param name="number" select="$number + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="html:tr">
<row>
<xsl:apply-templates/>
</row>
</xsl:template>
<xsl:template match="html:th|html:td">
<xsl:variable name="position" select="count(preceding-sibling::*) + 1"/>
<entry>
<xsl:if test="@colspan > 1">
<xsl:attribute name="namest">
<xsl:value-of select="concat('col',$position)"/>
</xsl:attribute>
<xsl:attribute name="nameend">
<xsl:value-of select="concat('col',$position + number(@colspan) - 1)"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan > 1">
<xsl:attribute name="morerows">
<xsl:value-of select="number(@rowspan) - 1"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</entry>
</xsl:template>
<xsl:template match="html:td_null">
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="count_columns">
<xsl:param name="table" select="."/>
<xsl:param name="row" select="$table/html:tr[1]"/>
<xsl:param name="max" select="0"/>
<xsl:choose>
<xsl:when test="local-name($table) != 'table'">
<xsl:message>Attempting to count columns on a non-table element</xsl:message>
</xsl:when>
<xsl:when test="local-name($row) != 'tr'">
<xsl:message>Row parameter is not a valid row</xsl:message>
</xsl:when>
<xsl:otherwise>
<!-- Count cells in the current row -->
<xsl:variable name="current_count">
<xsl:call-template name="count_cells">
<xsl:with-param name="cell" select="$row/html:td[1]|$row/html:th[1]"/>
</xsl:call-template>
</xsl:variable>
<!-- Check for the maximum value of $current_count and $max -->
<xsl:variable name="new_max">
<xsl:choose>
<xsl:when test="$current_count > $max">
<xsl:value-of select="number($current_count)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($max)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- If this is the last row, return $max, otherwise continue -->
<xsl:choose>
<xsl:when test="count($row/following-sibling::html:tr) = 0">
<xsl:value-of select="$new_max"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="count_columns">
<xsl:with-param name="table" select="$table"/>
<xsl:with-param name="row" select="$row/following-sibling::html:tr"/>
<xsl:with-param name="max" select="$new_max"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="count_cells">
<xsl:param name="cell"/>
<xsl:param name="count" select="0"/>
<xsl:variable name="new_count">
<xsl:choose>
<xsl:when test="$cell/@colspan > 1">
<xsl:value-of select="number($cell/@colspan) + number($count)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number('1') + number($count)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="count($cell/following-sibling::*) > 0">
<xsl:call-template name="count_cells">
<xsl:with-param name="cell"
select="$cell/following-sibling::*[1]"/>
<xsl:with-param name="count" select="$new_count"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$new_count"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
关于html - 将 XHTML 文章转换为 Docbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8189155/
我正在尝试创建一个 Django 网站,每次在本地主机上运行/articles/api/article 页面时:我都会收到此回溯: Environment: Request Method: GET R
我正在尽最大努力理解开放图谱协议(protocol)中的一切含义阅读 FB page在上面和 OGP Page .这在 FB 和 OGP 的世界中究竟意味着什么: Note that the Open
我的 HTML/CSS 中存在页脚与文章内容重叠的问题。是的,我一直在网上搜索但似乎没有任何效果,我希望你知道它有什么问题。我在这里做了一个codepen: CodePen LINK
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我可以将变量作为警报显示在函数中,但无法将变量传递给文章。我做错了什么? 我知道“a”保存了正确的信息,因为我已经通过警报显示了它。 我尝试使用以下方式传递变量:placeholderContent.
这个问题已经有答案了: Rails article helper - "a" or "an" (6 个回答) 已关闭 3 年前。 是否有类似 [#pluralize in ActiveSupport]
这个问题已经有答案了: Rails article helper - "a" or "an" (6 个回答) 已关闭 3 年前。 是否有类似 [#pluralize in ActiveSupport]
我有以下型号。 Book has Articles (Article has foreign key to Book) Article has Images (Article has upto #ma
我创建了一个页面,该页面显示了单个 类别下的所有帖子,即如果我单击类别音乐,我将获得与音乐类别相关的所有文章。 但我的目标是创建一个过滤选项,它可以过滤掉某些类别,并且只显示与您过滤的类别相关的所有帖
我使用这样的代码: $query = "SELECT introtext FROM #__content WHERE alias = '$alias'"; $db->setQuery($query);
我在主页上设置了一些特色文章。显示的所有文章似乎都剩下太多填充。我知道足以进入 css 并在 layout.css 上编辑 .itembody 的填充或边距,但似乎没有任何改变。我希望我的文章通过模块
ORM 中存储文章及其修订的最佳实践是什么?当我自己用SQL存储时,我曾经有以下结构: articles [id, parent_id, name, text] 通过parent_id,我可以轻松识
我的 HTML : Interest About Interest
我正在用jade构建一个nodejs、express、mongodb博客。 我的文件夹结构是:项目/ 模块/ 观点/ 索引.jade 应用程序.js 文章提供者内存.js 文章provider-mon
我的问题比较具体,至少对我来说是这样。具体是因为在做了很多搜索之后我找不到任何有用的东西。因此,正如标题所说,我正在寻找一种算法,它会发现输入中给出的两篇文章是否“匹配”,但不是通常的字符串匹配意义上
关闭。这个问题是off-topic .它目前不接受答案。 9年前关闭。 锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。 我无法弄清楚动态编程的原
我有这个问题。我正在建立一个社交网站,我必须在两栏中创建帖子。父容器是一个部分,元素“post”是样式为 float: left 的文章。我如何让滑到那些较短的下方创建的空白空间的帖子? 最佳答案 c
这里有几个关于文件与数据库的问题,但我仍然不确定使用什么以及为什么在我的案例中应该使用它。 我的网站上有很多 HTML 文章(长度在几百到几千字之间)。在数据库 (MySQL) 中,我有一个没有搜索索
微信公众号文章 Semantic Kernel —— LangChain 的替代品? [1] ,它使用的示例代码是Python ,他却发了这么一个疑问: 支持的语言对比(因为 Sem
我想编写一个 polymer 元素来显示一些 WordPress 文章。 http://www.jsv-lippstadt.de/?json=get_category_posts&slug=app
我是一名优秀的程序员,十分优秀!