【发布时间】:2015-10-08 21:20:08
【问题描述】:
我正在获取一个平面 HTML 源并将其转换为分层 DITA 文件s,以及它们关联的 .ditamap。
它是fiddled,但当然,<result-document> 在那里不起作用。
编辑:refiddled 是对问题的更小更简洁的反映。
我很接近。这代表了我的来源。它看起来很复杂,但实际上并非如此:结果文档将是 <concept> 元素之间的所有内容......无论其中的嵌套/复杂性如何。
<!--
this is an interim file while converting flat html
to a hierarchical DITA structure
-->
<concepts text-title="Manual" id="manual">
<concept id="chapter1">
<title>Chapter 1</title>
<conbody>
<p>contents in body will</p>
<lq><i>vary</i> widely</lq>
<concept id="subchapter1-1">
<title>Subchapter 1</title>
<conbody>
<table>table</table>
<lq>foo</lq>
</conbody>
</concept>
</conbody>
</concept>
<concept id="chapter2">
<title>Chapter 2</title>
<conbody>
<table>table</table>
<lq>foo <pre>code</pre></lq>
</conbody>
<concept id="subchapter2-1">
<title>Subchapter 1</title>
<conbody>
<table>table</table>
<lq><b>foo</b></lq>
</conbody>
</concept>
</concept>
</concepts>
这是我的xslt,我在困难的地方做了cmets。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs mf"
xmlns:mf="http://example.org/mf"
version="2.0">
<xsl:output
method="xml"
omit-xml-declaration="no"
doctype-system="../dtd/technicalContent/dtd/map.dtd"
doctype-public="-//OASIS//DTD DITA Map//EN"
encoding="UTF-8"
indent="yes"/>
<xsl:strip-space elements="*"/>
<!--
Source: monolithic XML file containing many nested <concept> topics
Transform outcomes:
1. Transform of source will create a DITA <map><topicref>
2. A <result-document> will write out each <concept> as a singular file
-->
<xsl:template match="/">
<map
title="{/concepts/@text-title}"
id="{/concepts/@id}">
<xsl:apply-templates/>
</map>
</xsl:template>
<xsl:template match="text()"/>
<xsl:template match="concepts">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="concept">
<xsl:variable name="path-filename" select="concat('/home/mike/dita/prodrun/',@id,'.dita')"/>
<!-- transform source to make the DITA <map> -->
<topicref href="{$path-filename}" type="concept">
<xsl:apply-templates/>
</topicref>
<!-- write out this <concept> to the file system -->
<xsl:result-document
method="xml"
encoding="UTF-8"
omit-xml-declaration="no"
indent="yes"
doctype-system="../../dtd/technicalContent/dtd/concept.dtd"
doctype-public="-//OASIS//DTD DITA Concept//EN"
href="{$path-filename}">
<concept id="new foo will be added here">
<!--
Below is one of my efforts. I need to select ALL, to stopping short of next <concept>
I also tried <for-each-group's .. to no avail
-->
<xsl:copy-of select="descendant::*[not(self::*)][preceding::concept[1]]"/>
</concept>
</xsl:result-document>
</xsl:template>
最后,我会得到ditamap,这部分有效。我的文件系统中也会有四个这样的文件:
<concept id="t20">
<title>Chapter 1</title>
<conbody>
<p>contents in body will</p>
<lq><i>vary</i> widely</lq>
</conbody>
</concept>
<concept id="subchapter1-1">
<title>Subchapter 1</title>
<conbody>
<table>table</table>
<lq>foo</lq>
</conbody>
</concept>
<concept id="chapter2">
<title>Chapter 2</title>
<conbody>
<table>table</table>
<lq>foo <pre>code</pre></lq>
</conbody>
</concept>
<concept id="subchapter2-1">
<title>Subchapter 1</title>
<conbody>
<table>table</table>
<lq><b>foo</b></lq>
</conbody>
</concept>
FWIW:我正在使用 OxygenXML,但我将在命令行中使用 Saxon 例行运行它。
旁注:这让我对文档类型、命名空间和动态验证的实用性大开眼界。
【问题讨论】: