DocBook XSL包含一个匹配所有元素的模板
<xsl:template match="*">
<xsl:message> .... </xsl:message>
</xsl:template>我需要用另一个模板覆盖它,因为我的源DoocBook树包含的不仅仅是XML。如果我在文件中指定这样的模板,它将覆盖DocBook XSL中的所有模板。似乎所有导入的模板都只按导入的顺序排序,而不是根据模板的具体程度排序。
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="http://docbook.org/ns/docbook" version="1.0">
<xsl:import href="docbook-xsl-ns/xhtml/docbook.xsl" />
<xsl:import href="copy.xsl"/>
<xsl:template match="/">
<xsl:apply-templates select="//db:book"/>
</xsl:template>
</xsl:stylesheet>copy.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<!-- go process attributes and children -->
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>示例XML源代码
<?xml version="1.0" encoding="UTF-8"?>
<root>
<http-host>localhost</http-host>
<book xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:svg="http://www.w3.org/2000/svg" xmlns:m="http://www.w3.org/1998/Math/MathML" xml:id="course.528" xml:lang="en" version="5.0">
<info>
<title>Postoperative Complications</title>
</info>
<chapter xml:id="chapter.1">
<title>INTRODUCTION</title>
<para>Postoperative complications are a constant threat to the millions ....</para>
</chapter>
</book>
<errors></errors>
</root>Xalan和xsltproc处理器都是如此。如何在不更改DocBook XSL源的情况下覆盖此模板。我试着调整优先级,但这不起作用。
发布于 2009-10-14 11:32:57
据我所知,您只想将copy.xsl的模板应用于非docbook元素。尝试在您的copy.xsl中更具体-通过在您的copy.xsl中更具体,该模板将被选择用于所有非文档元素。
copy.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform>
<xsl:template match="*[not(namespace-uri() = 'http://docbook.org/ns/docbook')]">
<xsl:element name="{local-name()}">
<!-- go process attributes and children -->
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>根据非DocBook节点中是否存在Docbook元素,您可能还需要限制在apply-templates部分应用的节点集(基于名称空间),并可能会混淆apply-templates流,以确保它可预测地处理它。希望这对你有用..
https://stackoverflow.com/questions/1556234
复制相似问题