【问题标题】:fix xslt bug for validation修复 xslt 错误以进行验证
【发布时间】:2013-04-30 06:56:09
【问题描述】:

我需要验证 XSLT 中 Invoice 元素的值:缺少元素 = 默认为 1(工作)...空白 = 默认为 1(工作)...但是 2 或字符串中的任何数字都不起作用,因为它一直返回到 1。

<xsl:template match="Transaction" >
  <Transaction invoice="{Invoice}">
    <xsl:attribute name="invoice">
      <xsl:choose>
        <xsl:when test="@Invoice and (@Invoice!='') and (@Invoice!='0')">
        <xsl:value-of select="@Invoice"/></xsl:when>
        <xsl:otherwise>1</xsl:otherwise>
      </xsl:choose>
     </xsl:attribute>
</xsl:template>

希望能得到你的帮助。将不胜感激。

谢谢

【问题讨论】:

  • Invoice 是输入 xml 中的属性还是节点?似乎,您总是在默认分支中运行。 invoice="{Invoice}this 使用 Invoice 作为节点,但 @Invoice 正在寻找 Invoice 作为属性。
  • 您的问题不清楚,但如果您向我们展示源文档中的 Transaction 元素示例,我们可能能够回答。

标签: xml validation xslt


【解决方案1】:

when条件下使用AND而不是and(好像只有小写才好)

从一个简单的条件开始,一次加一个,看看哪个不好:

<xsl:when test="@Invoice">

然后

<xsl:when test="@Invoice and (@Invoice!='')">

然后

<xsl:when test="@Invoice and (@Invoice!='') and (@Invoice!=0)">

虽然我会写

<xsl:when test="@Invoice and (@Invoice &gt; 0)">

【讨论】:

  • 最后一行它不能大于0,因为它是一个字符串。
  • 对不起,从你的问题看来它们是数字(“...but 2 or any numbers which are not working because it keeps return to 1”)
  • 对不起,我应该在字符串中说数字 :) 我要编辑我的帖子,谢谢
猜你喜欢
  • 1970-01-01
  • 2020-11-03
  • 2012-06-10
  • 2014-02-27
  • 1970-01-01
  • 2011-04-19
  • 1970-01-01
  • 2013-04-01
  • 2018-08-04
相关资源
最近更新 更多