我有下面的xsl标记,在该标记中,我将获取fpml:周期乘法器和fpml:周期的值,如下所示.xml中的标记是:-
<fpml:periodMultiplier>1</fpml:periodMultiplier>
<fpml:period>Y</fpml:period>在xsl中提取,如下所示
<Payindextenor>
<xsl:value-of select="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:periodMultiplier" />
<xsl:value-of select="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:period" />
</Payindextenor>所以Payindextenor的值是1Y。
现在,我想将空检查放在这个标记中,因为在即将到来的xml中,fpml:周期乘法器和fpml:句点也可能没有值。
因此,我在下面的xsl实现中尝试过,如果其中任何一个值是空的,那么它应该打印空,请通知它正确吗:-
<xsl:choose>
<xsl:when test="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:periodMultiplier
!= ' '
and
../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:period
!= ' '">
<xsl:value-of select="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:periodMultiplier" />
<xsl:value-of select="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:period" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'null'" />
</xsl:otherwise>
</xsl:choose>发布于 2015-03-07 15:37:34
这与your previous question中的情况完全相同--与包含单个空格的(非空)字符串' '进行比较,而实际需要的是检查空字符串。您可以使用与我为该问题建议的解决方案相同的解决方案,并使用normalize-space进行测试(它将只包含空格的空字符串和字符串视为"false“,其他任何内容都视为"true"):
<xsl:choose>
<xsl:when test="normalize-space(../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:periodMultiplier)
and
normalize-space(../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:period)">
<xsl:value-of select="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:periodMultiplier" />
<xsl:value-of select="../fpml:calculationPeriodDates
/fpml:calculationPeriodFrequency
/fpml:period" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'null'" />
</xsl:otherwise>
</xsl:choose>这将处理fpml:periodMultiplier或fpml:period元素不存在的情况,以及它们存在但为空的情况。
发布于 2015-03-07 15:25:41
正如Ian所说,将节点与单个空间进行比较与检查"null“非常不同,但假设您希望在periodMultiplier和period都为空时显示"null",则可以这样做:
<xsl:variable name="freq"
select="../fpml:calculationPeriodDates/fpml:calculationPeriodFrequency" />
<xsl:choose>
<xsl:when test="$freq/fpml:periodMultiplier != '' or
$freq/fpml:period != ''">
<xsl:value-of select="$freq/fpml:periodMultiplier" />
<xsl:value-of select="$freq/fpml:period" />
</xsl:when>
<xsl:otherwise>
<xsl:text>null</xsl:text>
</xsl:otherwise>
</xsl:choose>https://stackoverflow.com/questions/28915885
复制相似问题