我有以下用于转换的xml:
<IFX xmlns="http://www.ifxforum.org/181/ifxschema">
<MediaSvcRq>
<MediaAcctAdjAddRq>
<MediaAcctAdjInfo>
<MediaTrnType>Dispense</MediaTrnType>
<CurAmt>
<Amt>1800.00</Amt>
<CurCode>PHP</CurCode>
</CurAmt>
<MediaItem>
<MediaContainerId>Cassette 2</MediaContainerId>
<MediaType>Cash</MediaType>
<Count>3</Count>
<MediaBal>
<CurAmt>
<Amt>500.00</Amt>
<CurCode>PHP</CurCode>
</CurAmt>
<MediaTotal>
<MediaTotalType>Dispensed</MediaTotalType>
<Count>3</Count>
</MediaTotal>
</MediaBal>
</MediaItem>
<MediaItem>
<MediaContainerId>CashRetainBin</MediaContainerId>
<MediaType>Cash</MediaType>
<Count>3</Count>
<MediaBal>
<CurAmt>
<Amt>500.00</Amt>
<CurCode>PHP</CurCode>
</CurAmt>
<MediaTotal>
<MediaTotalType>Retained</MediaTotalType>
<Count>3</Count>
</MediaTotal>
</MediaBal>
</MediaItem>
<MediaItem>
<MediaContainerId>Cassette 3</MediaContainerId>
<MediaType>Cash</MediaType>
<Count>3</Count>
<MediaBal>
<CurAmt>
<Amt>100.00</Amt>
<CurCode>PHP</CurCode>
</CurAmt>
<MediaTotal>
<MediaTotalType>Dispensed</MediaTotalType>
<Count>3</Count>
</MediaTotal>
</MediaBal>
</MediaItem>
<MediaItem>
<MediaContainerId>CashRetainBin</MediaContainerId>
<MediaType>Cash</MediaType>
<Count>3</Count>
<MediaBal>
<CurAmt>
<Amt>100.00</Amt>
<CurCode>PHP</CurCode>
</CurAmt>
<MediaTotal>
<MediaTotalType>Retained</MediaTotalType>
<Count>3</Count>
</MediaTotal>
</MediaBal>
</MediaItem>
</MediaAcctAdjInfo>
</MediaAcctAdjAddRq>
</MediaSvcRq>
</IFX>
我希望得到以下结果:
<XML>
<!--Information of Message Container ID: Cassette 1-->
<F70><!--//MediaItem/MediaBal/CurAmt/Amt-->
</F70>
<F71><!--//MediaItem/MediaBal/CurAmt/CurCode-->
</F71>
<F72><!--//MediaItem/MediaBal/MediaTotal/Count-->
</F72>
<!--Information of Message Container ID: Cassette 2-->
<F73><!--//MediaItem/MediaBal/CurAmt/Amt-->
500.00
</F73>
<F74><!--//MediaItem/MediaBal/CurAmt/CurCode-->
PHP
</F74>
<F75><!--//MediaItem/MediaBal/MediaTotal/Count-->
3
</F75>
<!--Information of Message Container ID: Cassette 3-->
<F76><!--//MediaItem/MediaBal/CurAmt/Amt-->
100.00
</F76>
<F77><!--//MediaItem/MediaBal/CurAmt/CurCode-->
PHP
</F77>
<F78><!--//MediaItem/MediaBal/MediaTotal/Count-->
3
</F78>
<!--Information of Message Container ID: Cassette 4-->
<F79><!--//MediaItem/MediaBal/CurAmt/Amt-->
</F79>
<F80><!--//MediaItem/MediaBal/CurAmt/CurCode-->
</F80>
<F81><!--//MediaItem/MediaBal/MediaTotal/Count-->
</F81>
<F82><!--Sum of //MediaItem/Count for CashRetainBin-->
</F82>
对于每个Cassette,我尝试了以下内容:
<F70>
<xsl:value-of select="//ifx:MediaSvcRq/ifx:MediaAcctAdjAddRq/ifx:MediaAcctAdjInfo/ifx:MediaItem[ifx:MediaContainerId='Cassette 1']/ifx:MediaBal/ifx:CurAmt/ifx:Amt"/>
</F70>
我认为匹配盒式磁带会起作用。
我遇到的问题是CashRetainBin的总和。如何匹配消息容器ID以获取CashRetainBin的总和?
答案 0 :(得分:0)
这应该可以解决问题:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ifx="http://www.ifxforum.org/181/ifxschema" exclude-result-prefixes="ifx"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="ifx:MediaAcctAdjInfo">
<XML>
<xsl:call-template name="ProcessCassettes" />
<F82>
<xsl:value-of select="sum(ifx:MediaItem[ifx:MediaContainerId = 'CashRetainBin']/ifx:Count)"/>
</F82>
</XML>
</xsl:template>
<xsl:template name="ProcessCassettes">
<xsl:param name="cassetteNo" select="1" />
<xsl:variable name="startingNo" select="67 + 3 * $cassetteNo" />
<xsl:variable name="mediaItem" select="ifx:MediaItem[ifx:MediaContainerId = concat('Cassette ', $cassetteNo)]"/>
<xsl:element name="F{$startingNo}">
<xsl:value-of select="$mediaItem/ifx:MediaBal/ifx:CurAmt/ifx:Amt"/>
</xsl:element>
<xsl:element name="F{$startingNo + 1}">
<xsl:value-of select="$mediaItem/ifx:MediaBal/ifx:CurAmt/ifx:CurCode"/>
</xsl:element>
<xsl:element name="F{$startingNo + 2}">
<xsl:value-of select="$mediaItem/ifx:MediaBal/ifx:MediaTotal/ifx:Count"/>
</xsl:element>
<xsl:if test="$cassetteNo < 4">
<xsl:call-template name="ProcessCassettes">
<xsl:with-param name="cassetteNo" select="$cassetteNo + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>