简体   繁体   English

即使xslt1.0中不存在该值,也会显示该值

[英]value is displayed even if the value is not exist in xslt1.0

This is my xslt code : 这是我的xslt代码:

<xsl:choose>
  <xsl:when test="string-length(
                    //Record/CIMtrek_CI_OPEX_200910_FrDiv
                    /text())
                  != 0">
    <select size="1" 
            style="width:100%;" 
            name="CIMtrek_CI_OPEX_200910_FrDiv" 
            id="CIMtrek_CI_OPEX_200910_FrDiv">
      <option>
        <xsl:attribute name="selected">true</xsl:attribute>
        <xsl:value-of select="//Record
                              /CIMtrek_CI_OPEX_200910_FrDiv
                              /text()" />
      </option>
     <option value="S M-SPED">S M-SPED</option>
     <option value="S M-PPPVLD">S M-PPPVLD</option>
   </select>
  </xsl:when>
  <xsl:otherwise>
    <select size="1" 
            style="width:100%;" 
            name="CIMtrek_CI_OPEX_200910_FrDiv" 
            id="CIMtrek_CI_OPEX_200910_FrDiv">
      <option value="0">Select Keywords</option>
      <option value="S M-SPED">S M-SPED</option>
      <option value="S M-PPPVLD">S M-PPPVLD</option>
    </select>
  </xsl:otherwise>
</xsl:choose>

but when there is no value also the when condition is there always. 但是,当没有价值时,总是存在when条件。

I think this is the line cost problem bur not sure, 我认为这是不确定的线路成本问题,

<xsl:when 
  test="string-length(
          //Record/CIMtrek_CI_OPEX_200910_FrDiv/text()
        ) != 0">

How to fix this? 如何解决这个问题?

You don't show an example of input that's wrongly producing output, but I'll guess that it involves XML that might look like this: 您没有显示错误地产生输出的输入示例,但是我猜想它涉及的XML可能看起来像这样:

<CIMtrek_CI_OPEX_200910_FrDiv>
  <!--* no value here! *-->
</CIMtrek_CI_OPEX_200910_FrDiv>

If you don't want whitespace in the element to count as a value, then you need to change your test from string-length(...) != 0 to string-length(normalize-space(...)) != 0 or the equivalent. 如果您不希望元素中的空格计数为值,则需要将测试从string-length(...) != 0更改为string-length(normalize-space(...)) != 0或等效值。 Because of the way XSLT coerces things to Boolean, this can be written more tersely as normalize-space(...) -- some proficient XSLT programmers prefer that form, while others find the implicit type coercions distracting and prefer the longer more explicit form. 由于XSLT将事物强制转换为布尔值的方式,因此可以更简洁地将其写为normalize-space(...) -一些精通XSLT的程序员更喜欢这种形式,而其他人则发现隐式类型的强制分散了人们的注意力,而更喜欢更长的更明确的形式。

If your problem is as I have conjectured, then any of the following should help: 如果您的问题是我所猜想的,那么以下任何一项都应有所帮助:

<xsl:when 
  test="string-length(
          normalize-space(
            //Record/CIMtrek_CI_OPEX_200910_FrDiv/text()
          )
        ) != 0">

<xsl:when 
  test="normalize-space(
            //Record/CIMtrek_CI_OPEX_200910_FrDiv/text()
        ) != ''">

<xsl:when 
  test="normalize-space(
            //Record/CIMtrek_CI_OPEX_200910_FrDiv/text()
        )">

If that's not the problem, then you'll need to be more explicit about what your question is. 如果这不是问题,那么您需要更清楚地说明问题是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM