XSL转换:选择块而不选择正确的变量

时间:2013-09-24 09:44:40

标签: xml xslt xslt-1.0 xsl-choose

我正在处理一个xsl文件,该文件不断丢失地址行。 我修复了它,但似乎打破了它试图修复与修复相关的问题。 以下是我的代码中的示例:

  <addressLine2>
        <xsl:choose>
            <xsl:when test="number($houseNameNumberNumericCharacterLength) &gt;= number($houseNameNumberNonNumericCharacterLength)">
                <xsl:value-of select="mad:Address/mad:AddressLineTwo"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$addressLineOne"/>
            </xsl:otherwise>                
        </xsl:choose>   
  </addressLine2>
  <addressLine3>
        <xsl:choose>
            <xsl:when test="addressLine2 != '$addressLineOne'">
                <xsl:value-of select="$addressLineThree"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$addressLineTwo"/>
            </xsl:otherwise>
        </xsl:choose>
  </addressLine3>
  <addressLine4>
        <xsl:choose>
            <xsl:when test="addressLine3 = ($addressLineTwo)">
                <xsl:value-of select="$addressLineThree"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="mad:Address/mad:AddressLineFour"/>
            </xsl:otherwise>
        </xsl:choose>
  </addressLine4>

您可以假设AddressLine2始终映射到变量$ addressLineOne。 AddressLine2工作正常。 我遇到的问题是地址第3行。我测试

when addressLine2 = $addressLineOne然后choose value $addressLineThree

但地址是这样的:

Line1: (mapped from houseNumberHouseName)
Line2: $AddressLineOne
Line3: $AddressLineThree
Line4: /

我需要的是:

Line1: (mapped from houseNumberHouseName)
Line2: $AddressLineOne
Line3: $AddressLineTwo
Line4: $AddressLineThree

并且未从houseNumberHouseName映射AddressLine1:

Line1: $AddressLineOne
Line2: $AddressLineTwo
Line3: $AddressLineThree
Line4: /

有人可以指出为什么我选择的选择不起作用吗?

由于

1 个答案:

答案 0 :(得分:1)

也许你可以像这样简化:

<xsl:choose>
    <xsl:when test="number($houseNameNumberNumericCharacterLength) &gt;= number($houseNameNumberNonNumericCharacterLength)">
        <addressLine2><xsl:value-of select="mad:Address/mad:AddressLineTwo"/></addressLine2>
        <addressLine3><xsl:value-of select="$addressLineThree"/></addressLine3>
        <addressLine4><xsl:value-of select="mad:Address/mad:AddressLineFour"/></addressLine4>
    </xsl:when>
    <xsl:otherwise>
        <addressLine2><xsl:value-of select="$addressLineOne"/></addressLine2>
        <addressLine3><xsl:value-of select="$addressLineTwo"/></addressLine3>
        <addressLine4><xsl:value-of select="$addressLineThree"/></addressLine4>
    </xsl:otherwise>                
</xsl:choose>