【问题标题】:how to remove a tag having value  如何删除具有价值的标签
【发布时间】:2019-01-28 20:56:26
【问题描述】:

输入是:

<p>&#160;</p>

输出是:

<p></p>

我想删除输出文件中的空标签,因为&amp;#160; 是 nbsp 并且在输出中它被转换为空格,但我不希望这个标签带有空格。

输入是:

<div>
    <title>Operational Commands</title>
    <p>show ip nat filtershow ip nat interfaceshow ip nat interface-statistics</p>
<div>
    <title>Release Information</title>
    <p>Command introduced in Viptela Software Release 18.3.​</p>
</div>
<div>
    <title>Additional Information</title>
    <p>See the Configuring Transport-Side NAT article for your software release.</p>
    <p> </p>
</div>

我的 xslt 代码是:

<xsl:variable name='list' select='//div'/>

<xsl:template match='/'>

        <xsl:for-each select='$list'>
            <xsl:element name='section'>
                <xsl:apply-templates select='*[not(name(.)="div")]'/>

            </xsl:element>
        </xsl:for-each>

</xsl:template>

输出是:

 <section>
        <title>Operational Commands</title>
        <p>show ip nat filtershow ip nat interfaceshow ip nat interface-statistics</p>
    </section><section>
        <title>Release Information</title>
        <p>Command introduced in Viptela Software Release 18.3.​</p>
    </section><section>
        <title>Additional Information</title>
        <p>See the Configuring Transport-Side NAT article for your software release.</p>
        <p> </p>
    </section>

在最后一节中,&lt;p&gt; 标签有空间,被认为是空标签,那么我需要删除这个空标签。我怎样才能删除它?

【问题讨论】:

  • 这里的输入是:

    ASCII 格式的 nbsp

    i. e 160 ;
  • 如果您有任何现有的 XSLT 可以将该不间断空间“转换”为正常空间,那么您应该向我们展示该代码。目前尚不清楚您是要修复某些特定的 XSLT 代码还是要编写 XSLT 以从任何输入中删除任何 &lt;p&gt;&amp;#160;&lt;/p&gt; 元素。
  • 我在下面写了我的代码..
  • 请编辑您的问题以提供任何详细信息,而不是作为答案。还可以考虑向我们展示最少但完整的示例和信息,以便我们重现问题。您在“答案”中显示的 XSLT 部分根本不会创建任何 p 元素。它也不会将不间断空格之类的字符转换为空格。
  • 好的...那么我需要做些什么来删除空的

    标签?

标签: xml xslt tags space


【解决方案1】:

首先,包含不间断空格的元素不是空的。并且不间断空格不会在输出中“转换为空格”,除非您已指示样式表对其进行转换。

现在,要删除 &lt;p&gt;&amp;#160;&lt;/p&gt; 元素,您可以添加一个与之匹配的空模板:

<xsl:template match="p[.='&#160;']"/>

如果您愿意,您可以制作一个更通用的模板,删除所有空的和纯空格的 p 元素:

<xsl:template match="p[not(normalize-space(translate(., '&#160;', ' ')))]"/>

【讨论】:

  • 好。如果您的问题得到解答,请通过接受答案来关闭它。
  • 我不知道你的意思。
  • 其实我想删除xml中存在的所有空标签
  • 我的 xml 中有两个场景 1.

     

    2.
    当我申请时
  • 要删除所有空元素,您可以使用&lt;xsl:template match="*[...]"/&gt;。要删除一些空元素,可以使用&lt;xsl:template match="(p|dl)[...]"/&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 2022-08-23
  • 1970-01-01
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多