我需要一个样式表来转换我的docbook XML文件,以便它们现在包含XML:基本元素到我的部分标签。我该如何执行此操作(因为XML:基本需求系统和节点信息???)

输入:

<section xmlns="http://docbook.org/ns/docbook" xml:id="voidVisit" version="5">
<title>Void</title>

 <section>
  <title>Screenshot</title>
      <mediaobject>
          <imageobject>
              <imagedata fileref="screenshots/Dialog.png" />
          </imageobject>
      </mediaobject>
 </section>
</section>

输出:

      ...
      <section xml:id="void" version="5"
           xml:base="file:/C:/Projects/my/proj/trunk/spec/module/components/void.xml">
     <title>Void</title>
     <section>
        <title>Screenshot</title>
        <mediaobject>
           <imageobject>
              <imagedata fileref="screenshots/Dialog.png"/>
           </imageobject>
        </mediaobject>
     </section>
     ...
有帮助吗?

解决方案

在XSLT 2.0(XPATH 2.0)中 static-base-uri()base-uri() 可用于此目的.

这是一个工作示例:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/">
     <doc xml:base="{base-uri()}"/>
    </xsl:template>
</xsl:stylesheet>

当应用这种转换时,会产生想要的结果:

<doc xml:base="file:/C:/CVS-DDN/fxsl-xslt2/data/marrowtr.xml"/>

因此,您案件的完整转变是:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:d="http://docbook.org/ns/docbook">
 <xsl:output omit-xml-declaration="yes"/>

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

    <xsl:template match="/d:section">
     <xsl:copy>
       <xsl:attribute name="xml:base" select="base-uri(/)"/>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

在XSLT 1.0中,解决方案为 作为外部参数传递基础uri(全局 xsl:param>)转换。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top