0

我在 xslt 2.0 上有这个代码。

<xsl:template match="results">
  <xsl:choose>
    <xsl:when test="result">
    <xsl:if test="result/publication/@testdate='true'">
    <div class="publication-wrapper">
      <xsl:apply-templates/>
    </div>
    </xsl:if>
    <xsl:if test="result/publication/@testdate='false'">
    <div class="former-publication-wrapper">
      <xsl:apply-templates/>
    </div>
    </xsl:if>
    </xsl:when>
    <xsl:otherwise>
    <div class="publication publication-label" >None</div>
    </xsl:otherwise>
  </xsl:choose>            
</xsl:template>


<xsl:template match="result">
  <xsl:variable name="publication-uri" select="publication/@uri" />
  <xsl:variable name="publication-label" select="publication/@label" />
  <xsl:variable name="test" select="publication/@testdate" />
  <div class="publication">
    <div class="publication-label">
      <a href="{ov:getPublicationURL($publication-uri)}"><xsl:value-of select="$publication-label" /></a>
    </div>
    .
    .
    .
  </div>
</xsl:template>

我的 xml 是这样从 xquery 构建的:

<results id="publications">
  <result>
    <publication uri="hello" label="hello world" testdate="false"/>
  </result>
  <result>
    <publication uri="goodbye" label="goodbye world" whitelisted="false" testdate="true"/>
  </result>
</results>

如果模板结果中的 $test 为真,我想在 div 发布包装器中显示我的出版物,如果它为假,我想在前发布包装器中显示我的出版物。

在 <xsl:when test="result"> 我测试了几件事。使用 <xsl:when test="result/publication/@test='true'">,我有出版物,像 <xsl:when test="result/publication/@test='aaa'"> 我没有没有任何出版物。所以我假设在我的 xsl:when 我可以检查 $test 是否存在及其值。但是使用此代码,即使我知道有任何出版物,我也没有任何出版物。

4

0 回答 0