【问题标题】:xsl stylesheet and empty elementsxsl 样式表和空元素
【发布时间】:2023-03-23 12:21:01
【问题描述】:

我需要在 dublincore xml 上应用 xsl 来转换

<dc:description> blahblah </dc:description>

类似:

<descriptions>
 <description descriptionType="Abstract"> blahblah </description>
</descriptions>

我正在测试这个,但如果元素为空 我不想显示任何东西,而不是&lt;descriptions/&gt;

你应该如何纠正这个问题?

       <xsl:if test="dc:description">
            <descriptions>
                <xsl:for-each select="dc:description">
                <xsl:variable name="description" select="."/>
                <xsl:if test="$description !=''">
                    <description descriptionType="Abstract">
                        <xsl:value-of select="."/>
                    </description>
                </xsl:if>
                </xsl:for-each>
            </descriptions>
        </xsl:if>

【问题讨论】:

    标签: xslt


    【解决方案1】:
    <xsl:if test="dc:description/text()">
    

    仅当至少有一个非空dc:description 时才应为真。或者重复使用你在内部 if 和 say 中所做的相同测试

    <xsl:if test="dc:description != ''">
    

    a != 测试其中一侧是节点集,如果集合中有 any 节点,其值为 != 另一侧(这就是规范中有注释的原因如果 x 和 y 中的一个或两个是节点集,x != y 不一定与 not(x = y) 相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2020-03-13
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多