首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止将xmlns="“属性添加到由XSLT1.0生成的HTML元素

防止将xmlns="“属性添加到由XSLT1.0生成的HTML元素
EN

Stack Overflow用户
提问于 2013-04-08 02:48:54
回答 2查看 6.2K关注 0票数 4

我正在为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:

代码语言:javascript
复制
<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的一段代码:

代码语言:javascript
复制
<?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>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-08 04:15:08

正如Michael Kay所说,如果您不想在xhtml名称空间中使用div,请从您的xsl:stylesheet中删除默认名称空间(xmlns="http://www.w3.org/1999/xhtml")。

否则,您可以使用xsl:element构建元素并为其提供一个空的命名空间:

代码语言:javascript
复制
    <xsl:element name="div" namespace="">
        <xsl:attribute name="class">text-content</xsl:attribute>
        <xsl:text>...</xsl:text>
    </xsl:element>
票数 3
EN

Stack Overflow用户

发布于 2013-04-08 04:08:08

示例中的<div>文本结果元素位于命名空间http://www.w3.org/1999/xhtml中。如果您不想将其放入该名称空间中,则不要将其放入该名称空间中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15866373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档