XSLT 1.0 转换结构问题



我想要的结果是:

对于每个与//root/document/DetailGroup/Detail/Order/contract/@contractId匹配的//root/document/ins/@contractId,并且DetailSubtype是毛的,order type=Surrender

应汇总交易信息。需要总结的金额应该只full_surpartial_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>

试试这个

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes" omit-xml-declaration="yes"/>
    <!-- use a key to match contractId attributes -->
    <xsl:key name="kContract" match="Order" use="contract/@contractId"/>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="Document">
        <root>
            <xsl:apply-templates/>
        </root>
    </xsl:template>
    <xsl:template match="ins">
        <document>
            <person role="{descendant::role}" personId="{descendant::person/@personId}"/>
            <bet>
                <spar>
                    <at>
                        <xsl:attribute name="sum">
                            <xsl:value-of select="sum(key('kContract', @contractId)/descendant::completedAmount[parent::Transaction[TransactionSubtype = 'full_sur' or TransactionSubtype = 'partial_sur']])"/>
                        </xsl:attribute>
                    </at>
                </spar>
            </bet>
        </document>
    </xsl:template>
    <xsl:template match="DetailGroup"/>
</xsl:stylesheet>

相关内容

  • 没有找到相关文章

最新更新