首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在xsl中放置null检查

在xsl中放置null检查
EN

Stack Overflow用户
提问于 2015-02-26 14:23:54
回答 1查看 173关注 0票数 0

我有下面的输入xml,现在我正在使用xalan api进行xsl转换,下面是xml。

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<Report xmlns:fpml="http://www.fpml.org/FpML-5/confirmation" xmlns="http://www.eurexchange.com/EurexIRSFullInventoryReport" name="CB202 Full Inventory Report">
  <reportNameGrp>
    <CM>
      <acctTypGrp name="A1">
        <ProductType name="OIS">
          <currTypCod value="EUR">
            <rateIndex name="EONIA">
              <rateIndexTenor name="1D">
                <idxSource>EONIA</idxSource>
                <CCPTradeId id="612822">
                  <fpml:dataDocument fpmlVersion="5-0">
                    <fpml:trade>
                      <fpml:tradeHeader>
                        <fpml:partyTradeIdentifier>
                          <fpml:partyReference href="CPTY_612822"></fpml:partyReference>
                          <fpml:tradeId tradeIdScheme=""></fpml:tradeId>
                        </fpml:partyTradeIdentifier>
                        <fpml:partyTradeIdentifier>
                          <fpml:partyReference href="PO_612822"></fpml:partyReference>
                          <fpml:accountReference href="ACC_612822"></fpml:accountReference>
                          <fpml:tradeId tradeIdScheme="">9786042-2</fpml:tradeId>
                          <fpml:versionedTradeId>
                            <fpml:tradeId tradeIdScheme="">612822</fpml:tradeId>
                            <fpml:version>1</fpml:version>
                          </fpml:versionedTradeId>
                        </fpml:partyTradeIdentifier>
                        <fpml:tradeDate>2013-05-21</fpml:tradeDate>
                        <fpml:clearedDate>2013-11-13</fpml:clearedDate>
                      </fpml:tradeHeader>
                      <fpml:swap>
                        <fpml:swapStream id="fixedLeg_612822">
                          <fpml:payerPartyReference href="CPTY_612822"></fpml:payerPartyReference>
                          <fpml:receiverPartyReference href="PO_612822"></fpml:receiverPartyReference>
                          <fpml:calculationPeriodDates id="fixedLegCalcPeriodDates_612822">
                            <fpml:effectiveDate>
                              <fpml:unadjustedDate>2013-05-23</fpml:unadjustedDate>
                              <fpml:dateAdjustments>
                                <fpml:businessDayConvention>NONE</fpml:businessDayConvention>
                              </fpml:dateAdjustments>
                            </fpml:effectiveDate>
                            <fpml:terminationDate>
                              <fpml:unadjustedDate>2015-05-23</fpml:unadjustedDate>
                              <fpml:dateAdjustments>
                                <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                                <fpml:businessCenters>
                                  <fpml:businessCenter>EUTA</fpml:businessCenter>
                                </fpml:businessCenters>
                              </fpml:dateAdjustments>
                            </fpml:terminationDate>
                            <fpml:calculationPeriodDatesAdjustments>
                              <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                              <fpml:businessCenters>
                                <fpml:businessCenter>EUTA</fpml:businessCenter>
                              </fpml:businessCenters>
                            </fpml:calculationPeriodDatesAdjustments>
                            <fpml:calculationPeriodFrequency>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>Y</fpml:period>
                              <fpml:rollConvention>23</fpml:rollConvention>
                            </fpml:calculationPeriodFrequency>
                          </fpml:calculationPeriodDates>
                          <fpml:paymentDates>
                            <fpml:calculationPeriodDatesReference href="fixedLegCalcPeriodDates_612822"></fpml:calculationPeriodDatesReference>
                            <fpml:paymentFrequency>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>Y</fpml:period>
                            </fpml:paymentFrequency>
                            <fpml:payRelativeTo>CalculationPeriodEndDate</fpml:payRelativeTo>
                            <fpml:paymentDaysOffset>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>D</fpml:period>
                              <fpml:dayType>Business</fpml:dayType>
                            </fpml:paymentDaysOffset>
                            <fpml:paymentDatesAdjustments>
                              <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                              <fpml:businessCenters>
                                <fpml:businessCenter>EUTA</fpml:businessCenter>
                              </fpml:businessCenters>
                            </fpml:paymentDatesAdjustments>
                          </fpml:paymentDates>
                          <fpml:calculationPeriodAmount>
                            <fpml:calculation>
                              <fpml:notionalSchedule>
                                <fpml:notionalStepSchedule>
                                  <fpml:initialValue>100000000.00</fpml:initialValue>
                                  <fpml:currency>EUR</fpml:currency>
                                </fpml:notionalStepSchedule>
                              </fpml:notionalSchedule>
                              <fpml:fixedRateSchedule>
                                <fpml:initialValue>0.01200000</fpml:initialValue>
                              </fpml:fixedRateSchedule>
                              <fpml:dayCountFraction>ACT/360</fpml:dayCountFraction>
                            </fpml:calculation>
                          </fpml:calculationPeriodAmount>
                        </fpml:swapStream>
                        <fpml:swapStream id="floatingLeg_612822">
                          <fpml:payerPartyReference href="PO_612822"></fpml:payerPartyReference>
                          <fpml:receiverPartyReference href="CPTY_612822"></fpml:receiverPartyReference>
                          <fpml:calculationPeriodDates id="floatingLegCalcPeriodDates_612822">
                            <fpml:effectiveDate>
                              <fpml:unadjustedDate>2013-05-23</fpml:unadjustedDate>
                              <fpml:dateAdjustments>
                                <fpml:businessDayConvention>NONE</fpml:businessDayConvention>
                              </fpml:dateAdjustments>
                            </fpml:effectiveDate>
                            <fpml:terminationDate>
                              <fpml:unadjustedDate>2015-05-23</fpml:unadjustedDate>
                              <fpml:dateAdjustments>
                                <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                                <fpml:businessCenters>
                                  <fpml:businessCenter>EUTA</fpml:businessCenter>
                                </fpml:businessCenters>
                              </fpml:dateAdjustments>
                            </fpml:terminationDate>
                            <fpml:calculationPeriodDatesAdjustments>
                              <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                              <fpml:businessCenters>
                                <fpml:businessCenter>EUTA</fpml:businessCenter>
                              </fpml:businessCenters>
                            </fpml:calculationPeriodDatesAdjustments>
                            <fpml:calculationPeriodFrequency>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>Y</fpml:period>
                              <fpml:rollConvention>23</fpml:rollConvention>
                            </fpml:calculationPeriodFrequency>
                          </fpml:calculationPeriodDates>
                          <fpml:paymentDates>
                            <fpml:calculationPeriodDatesReference href="floatingLegCalcPeriodDates_612822"></fpml:calculationPeriodDatesReference>
                            <fpml:paymentFrequency>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>Y</fpml:period>
                            </fpml:paymentFrequency>
                            <fpml:payRelativeTo>CalculationPeriodEndDate</fpml:payRelativeTo>
                            <fpml:paymentDaysOffset>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>D</fpml:period>
                              <fpml:dayType>Business</fpml:dayType>
                            </fpml:paymentDaysOffset>
                            <fpml:paymentDatesAdjustments>
                              <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                              <fpml:businessCenters>
                                <fpml:businessCenter>EUTA</fpml:businessCenter>
                              </fpml:businessCenters>
                            </fpml:paymentDatesAdjustments>
                          </fpml:paymentDates>
                          <fpml:resetDates id="floatingLegresetDates_612822">
                            <fpml:calculationPeriodDatesReference href="floatingLegCalcPeriodDates_612822"></fpml:calculationPeriodDatesReference>
                            <fpml:resetRelativeTo>CalculationPeriodEndDate</fpml:resetRelativeTo>
                            <fpml:fixingDates>
                              <fpml:periodMultiplier>0</fpml:periodMultiplier>
                              <fpml:period>D</fpml:period>
                              <fpml:businessDayConvention>PRECEDING</fpml:businessDayConvention>
                              <fpml:businessCenters>
                                <fpml:businessCenter>EUTA</fpml:businessCenter>
                              </fpml:businessCenters>
                              <fpml:dateRelativeTo href="floatingLegresetDates_612822"></fpml:dateRelativeTo>
                            </fpml:fixingDates>
                            <fpml:resetFrequency>
                              <fpml:periodMultiplier>1</fpml:periodMultiplier>
                              <fpml:period>Y</fpml:period>
                            </fpml:resetFrequency>
                            <fpml:resetDatesAdjustments>
                              <fpml:businessDayConvention>MODFOLLOWING</fpml:businessDayConvention>
                              <fpml:businessCenters>
                                <fpml:businessCenter>EUTA</fpml:businessCenter>
                              </fpml:businessCenters>
                            </fpml:resetDatesAdjustments>
                          </fpml:resetDates>
                          <fpml:calculationPeriodAmount>
                            <fpml:calculation>
                              <fpml:notionalSchedule>
                                <fpml:notionalStepSchedule>
                                  <fpml:initialValue>100000000.00</fpml:initialValue>
                                  <fpml:currency>EUR</fpml:currency>
                                </fpml:notionalStepSchedule>
                              </fpml:notionalSchedule>
                              <fpml:floatingRateCalculation>
                                <fpml:floatingRateIndex>EUR-EONIA-OIS-COMPOUND</fpml:floatingRateIndex>
                              </fpml:floatingRateCalculation>
                              <fpml:dayCountFraction>ACT/360</fpml:dayCountFraction>
                            </fpml:calculation>
                          </fpml:calculationPeriodAmount>
                        </fpml:swapStream>
                      </fpml:swap>
                      <fpml:documentation>
                        <fpml:masterAgreement>
                          <fpml:masterAgreementType masterAgreementTypeScheme="">ISDA</fpml:masterAgreementType>
                        </fpml:masterAgreement>
                        <fpml:contractualDefinitions>ISDA2006</fpml:contractualDefinitions>
                      </fpml:documentation>
                    </fpml:trade>
                    <fpml:party id="CPTY_612822">
                      <fpml:partyId>EUREX</fpml:partyId>
                      <fpml:partyName>EUREX</fpml:partyName>
                    </fpml:party>
                    <fpml:party id="PO_612822">
                      <fpml:partyId>BOSLO</fpml:partyId>
                      <fpml:partyName>plc.</fpml:partyName>
                    </fpml:party>
                    <fpml:account id="ACC_612822">
                      <fpml:accountId>BOSLO_A1</fpml:accountId>
                      <fpml:accountBeneficiary href="PO_612822"></fpml:accountBeneficiary>
                    </fpml:account>
                  </fpml:dataDocument>
                  <novDateTime>2013-11-13 17:50:44.773</novDateTime>
                </CCPTradeId>
              </rateIndexTenor>
            </rateIndex>
          </currTypCod>
        </ProductType>
      </acctTypGrp>
    </CM>
  </reportNameGrp>
</Report>

正如你可以看到,从上面的xml,我正在尝试读取的tradeid方案参数的值是9786042-2现在我想放一个检查,这是值不存在于交易id方案参数,然后null是显示,以便我已经提出了下面的xsl,但仍然对于cses,其中tradeid方案参数的值不在那里,null不更新,在那些情况下,请建议如何填充null的那些情况。

代码语言:javascript
复制
<!-- Main template starts -->

<xsl:template match="/eur:Report">
  <EurexMessage>
    <EurexFlows>
      <xsl:apply-templates select=".//eur:rateIndexTenor" />
      <!-- select="eur:reportNameGrp/eur:CM/eur:acctTypGrp/eur:ProductType/eur:currTypCod/eur:rateIndex/eur:rateIndexTenor" 
                    /> -->

    </EurexFlows>
  </EurexMessage>
</xsl:template>


<!-- sub template starts -->
<xsl:template match="eur:rateIndexTenor">
  <xsl:for-each select="eur:CCPTradeId">
    <EurexMessageObject>

      <!-- ####***** contact id is nul not displayd ****##### ----->
      <ContractID>
        <xsl:choose>
          <xsl:when test="fpml:dataDocument/*/*/fpml:partyTradeIdentifier/fpml:tradeId/@tradeIdScheme !=' '">
            <xsl:value-of
                select="fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="'null'" />
          </xsl:otherwise>
        </xsl:choose>
      </ContractID>
    </EurexMessageObject>
  </xsl:for-each>
</xsl:template>
EN

回答 1

Stack Overflow用户

发布于 2015-02-26 14:53:47

表达式something != ' '将生成

如果存在任何不等于

  • truesomething,则为' '
  • false (如果没有somethings

,则为单个something;如果所有something等于' ',则为单个something

在本例中,两个something都等于'' (空字符串)。因为这两个参数都不等于' ',所以这里的结果是true

如果我理解正确的话,您希望在tradeIdScheme不是空白或空格的地方输出tradeId,如果没有这样的null,则输出tradeId。

如果是这样,应该是这样的:

代码语言:javascript
复制
<ContractID>
  <xsl:variable name="foundTradeId"
      select="fpml:dataDocument/*/*/fpml:partyTradeIdentifier/fpml:tradeId
                                         [normalize-space(@tradeIdScheme)]" />
  <xsl:value-of select="$foundTradeId" />
  <xsl:if test="not($foundTradeId)">null</xsl:if>
</ContractID>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28735817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档