XSLT:如何避免在HTML的属性中添加自闭标签

时间:2018-12-19 22:11:57

标签: html xml xslt tags

我是XSLT的新手。我正在尝试调试几年前编写的XSLT(2.0版)问题。 XSLT代码的一部分如下:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
        <xsl:output indent="yes" doctype-public="-//W3C//DTD HTML 4.0//EN" use-character-maps="m1"/>
        <xsl:character-map name="m1">
            <xsl:output-character character="&#141;" string=" "/>
        </xsl:character-map>
        <xsl:strip-space elements="*"/>
...
...
        <xsl:template match="PARA|PARASTYLE">
            <xsl:choose>
                <xsl:when test="@style-name-escaped or (ancestor::TABLE and not(text())) or (not(*) and not(text()))">
                    <div>
                        <xsl:if test="@style-name-escaped">
                            <xsl:attribute name="class">
                                <xsl:value-of select="@style-name-escaped"/>
                            </xsl:attribute>
                        </xsl:if>
                        <xsl:if test="(ancestor::TABLE and not(text())) or (not(*) and not(text()))">
                            <xsl:attribute name="style">
                                <xsl:text>margin-bottom=10pt</xsl:text>
                            </xsl:attribute>
                            <xsl:text/>
                        </xsl:if>
                        <xsl:apply-templates />
                    </div>
                </xsl:when>
...
..

此XSLT如下将XML转换为HTML。基本上是在添加一个带有自闭标签的属性,如下所示:

<div class="Normal-Level">
  <div style="margin-bottom=10pt"/>
</div>

,这会由于自闭标签而导致在某些浏览器中显示问题。我想做的是输出如下所示,属性具有open和close标签:

   <div class="Normal-Level">
      <div style="margin-bottom=10pt">
      </div>
    </div>

我在线上进行了研究,但是语法似乎适合添加属性。感谢您的帮助

1 个答案:

答案 0 :(得分:1)

尝试将method="html"添加到xsl:output元素。

相关问题