0
這是我的XML文件:重複標籤的打印計數一次
<limitCheckApproved>
<correlationId correlationIdScheme="tttt">SEF_correlationId</correlationId>
<sequenceNumber>1</sequenceNumber>
<party id="party1">
<partyId>CLIENT1</partyId>
</party>
<party id="party2">
<partyId>BARCGB2L</partyId>
</party>
<party id="clearingBroker1">
<partyId>DB</partyId>
</party>
<party id="DCO">
<partyId>LCH</partyId>
</party>
<party id="ExecutionFacility">
<partyId>SEF1</partyId>
</party>
</limitCheckApproved>
這是我的XSLT文件:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements= "*"/>
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="limitCheckApproved/correlationId">
<FPCorID>
<xsl:attribute name = "FPCorIDSch">
<xsl:value-of select = "correlationId/@correlationIdScheme"/>
</xsl:attribute>
<xsl:value-of select = "correlationId"/>
</FPCorID>
</xsl:template>
<xsl:template match = "limitCheckApproved/party">
<FpNoOfPartyIDs>
<xsl:value-of select="count(/limitCheckApproved/party)"/>
</FpNoOfPartyIDs>
<FpPartyID>
<xsl:value-of select = "@id" />
</FpPartyID>
<FpPartyIDValue>
<xsl:value-of select = "partyId" />
</FpPartyIDValue>
</xsl:template>
</xsl:stylesheet>
這是輸出:
<limitCheckApproved>
<FPCorID correlationIdScheme="tttt">SEF_correlationId</FPCorID>
<FpNoOfPartyIDs>5</FpNoOfPartyIDs>
<FpPartyID>party1</FpPartyID>
<FpPartyIDValue>CLIENT1</FpPartyIDValue>
<FpNoOfPartyIDs>5</FpNoOfPartyIDs>
<FpPartyID>clearingBroker1</FpPartyID>
<FpPartyIDValue>CM1</FpPartyIDValue>
<FpNoOfPartyIDs>5</FpNoOfPartyIDs>
<FpPartyID>LimitsHub</FpPartyID>
<FpPartyIDValue>Traiana</FpPartyIDValue>
<FpNoOfPartyIDs>5</FpNoOfPartyIDs>
<FpPartyID>ExecutionFacility</FpPartyID>
<FpPartyIDValue>SEF1</FpPartyIDValue>
<FpNoOfPartyIDs>5</FpNoOfPartyIDs>
<FpPartyID>DCO</FpPartyID>
<FpPartyIDValue>LCH</FpPartyIDValue>
</limitCheckApproved>
我需要什麼是FpNoOfPartyIDs標籤只打印一次,而其他標籤FpPartyIDValue和FpNoOfPartyIDs要打印正常。 但我找不到一個正確的方式來指定此。
我已經嘗試了幾個方法可以做到這一點:
.
.
.
<xsl:if test = "partyId = 'party1'">
<FpNoOfPartyIDs>
<xsl:value-of select="count(/limitCheckApproved/party)"/>
</FpNoOfPartyIDs>
</xsl:if>
.
.
但是這種方法以後會導致錯誤。
此外,我試圖做一個模板內的一切:
<xsl:template match="limitCheckApproved">
<limitCheckApproved>
.
.
.
<FpNoOfPartyIDs>
<xsl:value-of select="count(/limitCheckApproved/party)"/>
</FpNoOfPartyIDs>
<xsl:for-each select = "party">
<FpPartyID>
<xsl:value-of select = "@id" />
</FpPartyID>
<FpPartyIDValue>
<xsl:value-of select = "partyId" />
</FpPartyIDValue>
</xsl:for-each>
</limitCheckApproved>
</xsl:template>
但有一個更好的方式來做到這一點?
http://stackoverflow.com/help/someone-answers – 2015-05-30 16:59:53