【问题标题】:XSLT: Adding a processing instruction at the end of the fileXSLT:在文件末尾添加处理指令
【发布时间】:2011-01-14 19:47:53
【问题描述】:

我在一大堆 .xml 文件的末尾有一个<?hard-pagebreak?> PI(即,在最后一个节点之后的新行上?XSLT 执行此操作的最佳方式是什么?

示例输入:

<?xml version="1.0" encoding="UTF-8"?>
<section version="5"
         xml:id="summary"
         xreflabel="Issues Summary"
         xmlns="http://docbook.org/ns/docbook">
...stuff
</section>
<!-- need page break here -->

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    这是你要找的吗?

    <xsl:template match="/">
      <RootNode> 
      </RootNode>
      <xsl:processing-instruction name="hard-pagebreak" />
    </xsl:template>
    

    更新 下面是上面的改进版本,它也复制了源 XML 文档

    <xsl:template match="/">
      <xsl:apply-templates/>
      <xsl:processing-instruction name="hard-pagebreak" />
    </xsl:template>
    
    <xsl:template match="node() | @*">
      <xsl:copy>
         <xsl:apply-templates select="node() | @*" />
      </xsl:copy>
    </xsl:template>
    

    【讨论】:

    • 不 :( 这杀死了我 xml 文件的内容。我将把我的问题更新为我的示例 .xml 的样子
    • 部分只是您自己的 xsl 代码的占位符。您应该在关闭输出中的最后一个标签后简单地添加一个 ,如this answer所示。
    • 文档根目录没有属性
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2013-10-16
      相关资源
      最近更新 更多