1

我会检查文档是否包含给定的值和 xpath,如果它确实使用了选定的值,则使用另一个值。我在 XSLT 方面真的很糟糕,但这是我开始的:

  <xsl:choose>
          <xsl:when test="p//section.std[@type = 'SpecialSection']/p/img/@alt">
            <xsl:apply-templates select="p//section.std[@type = 'SpecialSection']/p/img/@alt"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="p//meta-data.titles/meta-data.title"/>
          </xsl:otherwise>
        </xsl:choose>         

当前未选择任何值。我怀疑我不能像以前那样编写我的选择测试。我不确定空值是否计算为布尔值。基本上我想测试第一个 xpath 是否返回一个值以及它是否使用它,如果不使用块中的那个。

有什么帮助吗?

4

1 回答 1

1

您可以仅使用以下单个表达式(以下select属性xsl:variable)选择想要的节点:

<xsl:variable select=
 "p//section.std[@type = 'SpecialSection']/p/img/@alt
 |
  p[not(.//section.std[@type = 'SpecialSection']/p/img/@alt)]
                                           //meta-data.titles/meta-data.title
 "/>
于 2012-09-13T03:08:46.080 回答