使用XSLT(@href)创建撰写的文档 [英] Create Composed Documents with XSLT (@href)

查看:102
本文介绍了使用XSLT(@href)创建撰写的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为所有引用的文档创建节点树,并使用XSLT将其存储到变量中? (我正在使用XSLT 2.0)

How can I create a node-tree for all my referenced documents and store it into a variable with XSLT? (I´m using XSLT 2.0)

这是我的文件结构:

  1. 文档.XML包含所有特定于语言的文档,如ditamaps
    <map> <navref mapref="de-DE/A.2+X000263.ditamap"/> <navref mapref="en-US/A.2+X000263.ditamap"/> <navref mapref="es-ES/A.2+X000263.ditamap"/> </map>
  2. 语言特定手册(.ditamap)-可能有多个文档
    <bookmap id="X000263" xml:lang="de-DE"> <chapter href="A.2+X000264.ditamap"/> </bookmap>
  3. 每本手册的

  4. <map id="X000264" xml:lang="de-DE"> <topicref href="A.2+X000265.ditamap"/> </map>
  5. 内容(.dita)或 SUB章(.ditamap)
    <map id="X000265" xml:lang="de-DE"> <topicref href="A.2+X000266.dita"/> <topicref href="A.2+X000269.dita"/> <topicref href="A.2+X000267.ditamap"/> </map>
  1. Root Document .XML contains all language specific documents as ditamaps
    <map> <navref mapref="de-DE/A.2+X000263.ditamap"/> <navref mapref="en-US/A.2+X000263.ditamap"/> <navref mapref="es-ES/A.2+X000263.ditamap"/> </map>
  2. Language specific manuals (.ditamap) - multiple documents possible
    <bookmap id="X000263" xml:lang="de-DE"> <chapter href="A.2+X000264.ditamap"/> </bookmap>
  3. Chapters for each manual
    <map id="X000264" xml:lang="de-DE"> <topicref href="A.2+X000265.ditamap"/> </map>
  4. Contents (.dita) or SUB-Chapters (.ditamap)
    <map id="X000265" xml:lang="de-DE"> <topicref href="A.2+X000266.dita"/> <topicref href="A.2+X000269.dita"/> <topicref href="A.2+X000267.ditamap"/> </map>

我的目标是建立一个完整的xml树(您可以说是一个组成"文档),并将所有文件正确嵌套到它们的给定父节点的引用中.

I´m aiming for a complete xml-tree (you could say a 'composed' document) with all files correctly nested into their reference giving parent nodes.

是否有一种简单的方法来创建带有<xsl:copy-of>的组合文档(也许具有多个'select'选项?

Is there an easy way to create a composed document with <xsl:copy-of> (maybe with mutliple 'select' options?

推荐答案

您将需要在引用之后编写模板,例如

You would need to write templates following the references e.g.

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* , node()"/>
  </xsl:copy>
</xsl:template>

复制不需要特殊处理的元素,然后

to copy elements that don't need special treatment, then

<xsl:template match="navref[@mapref]">
  <xsl:apply-templates select="doc(@mapref)/node()"/>
</xsl:template>

<xsl:template match="chapter[@href] | topicref[@href]">
  <xsl:apply-templates select="doc(@href)/node()"/>
</xsl:template>

<xsl:variable name="nested-tree">
  <xsl:apply-templates select="/*"/>
</xsl:variable>

如果您要编写其他模板,然后要处理变量,则可以使用模式来分隔处理步骤:

If you want to write other templates then to process the variable it might make sense to use modes to separate processing steps:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

<xsl:template match="@* | node()" mode="#all">
  <xsl:copy>
    <xsl:apply-templates select="@* , node()" mode="#current"/>
  </xsl:copy>
</xsl:template>

<xsl:variable name="composed-doc">
   <xsl:apply-templates select="/*" mode="compose"/>
</xsl:variable>

<xsl:template match="navref[@mapref]" mode="compose">
  <xsl:apply-templates select="doc(@mapref)/node()" mode="compose"/>
</xsl:template>

<xsl:template match="chapter[@href] | topicref[@href]" mode="compose">
  <xsl:apply-templates select="doc(@href)/node()" mode="compose"/>
</xsl:template>

</xsl:stylesheet>

这篇关于使用XSLT(@href)创建撰写的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆