我想要的結果是:XSLT 1.0變換結構問題
對於有//root/document/DetailGroup/Detail/Order/contract/@contractId
匹配每個//root/document/ins/@contractId
和DetailSubtype
是毛,order type=Surrender
。
應彙總交易信息。需要總結的數量只應該是full_sur
和partial_sur
,其他所有都應該被忽略
而且他們需要一個特定的結構,每個匹配邏輯一次。
首先需要將XML文件轉化:
<Document>
<ins contractId="670">
<Role>
<person personId="60"/>
<role>INS</role>
</Role>
</ins>
<ins contractId="477">
<Role>
<person personId="60"/>
<role>OWN</role>
</Role>
</ins>
<DetailGroup>
<Detail type="detailgross" DetailId="25">
<DetailSubtype>GROSS</DetailSubtype>
<Order type="Surrender">
<contract contractId="477"/>
<Transaction>
<Transaction>
<completedAmount>1443.08</completedAmount>
<TransactionSubtype>yield</TransactionSubtype>
</Transaction>
<Transaction>
<completedAmount>100.00</completedAmount>
<TransactionSubtype>fee</TransactionSubtype>
</Transaction>
<Transaction>
<completedAmount>200.00</completedAmount>
<TransactionSubtype>full_sur</TransactionSubtype>
</Transaction>
</Transaction>
</Order>
</Detail>
<Detail type="detailgross" DetailId="24">
<DetailSubtype>gross</DetailSubtype>
<Order type="Surrender">
<contract contractId="670"/>
<Transaction>
<Transaction>
<completedAmount>1443.08</completedAmount>
<TransactionSubtype>fee</TransactionSubtype>
</Transaction>
<Transaction>
<completedAmount>100.00</completedAmount>
<TransactionSubtype>full_sur</TransactionSubtype>
</Transaction>
<Transaction>
<completedAmount>1000.00</completedAmount>
<TransactionSubtype>partial_sur</TransactionSubtype>
</Transaction>
</Transaction>
</Order>
</Detail>
</DetailGroup>
</Document>
然後他們如何需要看:
<root>
<document>
<person role="INS" personId="60">
</person>
<bet>
<spar>
<at sum="1100"/>
</spar>
</bet>
</document>
<document>
<person role="OWN" personId="60">
</person>
<bet>
<spar>
<at sum="200"/>
</spar>
</bet>
</document>
</root>
編輯:我只能用XSLT 1.0
<xsl:template name="example">
<xsl:variable name="detailId" select="//Document/DetailGrooup/Detail/Order/contract"/>
<xsl:for-each select="//Document/ins[@contractId=$detailId/@contractId]">
<document>
<person>
<xsl:attribute name="Role">
<xsl:value-of select="//Document/Role"/>
</xsl:attribute>
<xsl:attribute name="personId">
<xsl:value-of select="//Document/Role/Person/@PersonId"/>
</xsl:attribute>
</person>
<bet>
<spar>
<xsl:if test=".././DetailGrooup/Detail[DetailSubtype='GROSS' and ./Order/@type='Surrender' and /Order/Transaction/Transaction/TransactionSubtype='full_sur']">
<xsl:attribute name="at">
<xsl:value-of select="sum(//Document/DetailGrooup/Detail/Order[/contract/@contractId='@contractId']/Transaction/Transaction/completedAmount)"
</xsl:attribute>
</xsl:if>
</spar>
</bet>
</document>
</xsl:for-each>
</xsl:template>
問題是什麼?我只看到要求。您可以添加您嘗試過的XSLT並解釋您遇到問題的位置嗎? –
嗨!對於最近的答案感到抱歉,我會稍微編輯一下我試圖做什麼,然後失敗。我遇到的問題是將正確的contractIds匹配在一起。 –