我正在为phpdoc2创建一个模板,并且当文档是从我的模板创建时,我想弄清楚如何防止属性xmlns="http://www.w3.org/1999/xhtml"被添加到生成的HTML的根级元素中。我在模板中的.xsl文件生成包含html片段的文件,这就是为什么<html>标记不是根级元素的原因。phpdoc 2似乎使用了XSLT v1.0,所以这限制了我的选择。在进行了一些搜索之后,最常见的答案是在每个.xsl文件的<xsl:stylesheet>标记上使用exclude-result-prefixes属性,并将其值设置为#all或#default,因为您不能只将xmlns用作要直接排除的名称空间。但我尝试了一下,在我的模板中的每个.xsl文件上设置了exclude-result-prefixes,但都不起作用。
按照要求,下面是我的一个.xsl文件api-doc.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="#all">
<xsl:output indent="no" method="html"/>
<xsl:include href="chrome.xsl"/>
<xsl:include href="api-doc/property.xsl"/>
<xsl:include href="api-doc/class.xsl"/>
<xsl:include href="api-doc/constant.xsl"/>
<xsl:include href="api-doc/function.xsl"/>
<xsl:include href="api-doc/docblock.xsl"/>
<xsl:include href="api-doc/file.xsl"/>
<xsl:template name="content">
<xsl:apply-templates select="/project/file[@path=$path]"/>
</xsl:template>
</xsl:stylesheet>这是api-doc/file.xsl的一段代码:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="#all">
<xsl:output indent="no" method="html"/>
<xsl:template match="file">
<div class="text-content">
<!-- ... -->
</div>
</xsl:template>
</xsl:stylesheet>添加了xmlns="http://www.w3.org/1999/xhtml"属性的元素是<div class="text-content"></div>。
发布于 2013-04-08 04:15:08
正如Michael Kay所说,如果您不想在xhtml名称空间中使用div,请从您的xsl:stylesheet中删除默认名称空间(xmlns="http://www.w3.org/1999/xhtml")。
否则,您可以使用xsl:element构建元素并为其提供一个空的命名空间:
<xsl:element name="div" namespace="">
<xsl:attribute name="class">text-content</xsl:attribute>
<xsl:text>...</xsl:text>
</xsl:element>发布于 2013-04-08 04:08:08
示例中的<div>文本结果元素位于命名空间http://www.w3.org/1999/xhtml中。如果您不想将其放入该名称空间中,则不要将其放入该名称空间中。
https://stackoverflow.com/questions/15866373
复制相似问题