繁体   English   中英

在XSLT1.0中使用muenchian基于字段值对元素进行分组

[英]Grouping of the elements based on the field value using muenchian in XSLT1.0

请求xml ..

<tem:responseDA xmlns:tem="http://tempuri.org">
<tem:outputData>   
<tem:dictionary id="AutoOutputs">    

<tem:list numOfItems="2">       
<tem:item>       
<tem:field dataType="double" name="DOWNPAYMENT">2000.00</tem:field>
</tem:item>     
<tem:item>       
<tem:field dataType="double" name="DOWNPAYMENT">3000.00</tem:field>
</tem:item>
</tem:list>  
<tem:list numOfItems="2">       
<tem:item>       
<tem:field dataType="string" name="CAMPAIGNCODE">A</tem:field>\
</tem:item>
<tem:item>       
<tem:field dataType="string" name="CAMPAIGNCODE">B</tem:field>
</tem:item>
</tem:list>   
<tem:list numOfItems="2">       
<tem:item>      
<tem:field dataType="double" name="BALLOONPAYMENT">4000.00</tem:field>
</tem:item>
<tem:item>       
<tem:field dataType="double" name="BALLOONPAYMENT">5000.00</tem:field>
</tem:item>
</tem:list>       
</tem:dictionary>
</tem:outputData>
</tem:responseDA>

现在,我需要根据该字段中的“ numofitems”对广告系列进行分组。

输出应该是..

<ns:FinalPricingQuoteResponse xmlns:ns="http://corp.alahli.com/middlewareservices/CreditVerificationService/1.1/" xmlns:tem="http://tempuri.org">
<ns:PricingQuoteOutput>
<ns:Campaigns>
<ns:campaignNumber>A</ns:campaignNumber>
<ns:downPayment>2000.00</ns:downPayment>
<ns:ballonPayment>4000.00</ns:ballonPayment>
</ns:Campaigns>
<ns:Campaigns>
<ns:campaignNumber>B</ns:campaignNumber>
<ns:downPayment>3000.00</ns:downPayment>
<ns:ballonPayment>5000.00</ns:ballonPayment>
</ns:Campaigns>
</ns:PricingQuoteOutput>
</ns:FinalPricingQuoteResponse>

您能否帮助我进行XSLT1.0的muenchian分组。

问候,伊尼安

不知道您所说的Münchian分组是什么意思。 大概您每次都有3个列表(具有可变数量的条目,您可以这样做:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
        xmlns:ns="http://corp.alahli.com/middlewareservices/CreditVerificationService/1.1/"
        xmlns:tem="http://tempuri.org"
        exclude-result-prefixes="xd"
        version="1.0">

        <xsl:output indent="yes" method="xml"/>

        <xsl:template match="/">
            <ns:FinalPricingQuoteResponse>
                <xsl:apply-templates select="tem:responseDA/tem:outputData/tem:dictionary" />
            </ns:FinalPricingQuoteResponse>
        </xsl:template>

        <xsl:template match="tem:dictionary">
            <ns:PricingQuoteOutput>
                <xsl:apply-templates select="tem:list[position()=1]" />
            </ns:PricingQuoteOutput>
        </xsl:template>

        <xsl:template match="tem:list[position()=1]">
            <xsl:apply-templates select="tem:item/tem:field[@name='DOWNPAYMENT']" />
        </xsl:template>

        <xsl:template match="tem:field[@name='DOWNPAYMENT']">
            <xsl:variable name="pos" select="position()" />
            <ns:Campaigns>
                <ns:campaignNumber><xsl:value-of select="/tem:responseDA/tem:outputData/tem:dictionary/tem:list[position()=2]/tem:item[position()=$pos]/tem:field"/></ns:campaignNumber>
                <ns:downPayment><xsl:value-of select="."/></ns:downPayment>
                <ns:ballonPayment><xsl:value-of select="../../../tem:list[position()=3]/tem:item[position()=$pos]/tem:field"/></ns:ballonPayment>
            </ns:Campaigns>
        </xsl:template>
    </xsl:stylesheet>

请注意两个不同的XPath(选择其中一个并坚持使用)以选择匹配的字段。 当然,这取决于列表的显示顺序,这可能很脆弱。 因此,稍微健壮的版本将是:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
        xmlns:ns="http://corp.alahli.com/middlewareservices/CreditVerificationService/1.1/"
        xmlns:tem="http://tempuri.org"
        exclude-result-prefixes="xd"
        version="1.0">

        <xsl:output indent="yes" method="xml"/>

        <xsl:template match="/">
            <ns:FinalPricingQuoteResponse>
                <xsl:apply-templates select="tem:responseDA/tem:outputData/tem:dictionary" />
            </ns:FinalPricingQuoteResponse>
        </xsl:template>

        <xsl:template match="tem:dictionary">
            <ns:PricingQuoteOutput>
                <xsl:apply-templates select="tem:list[tem:item/tem:field[@name='DOWNPAYMENT']]" />
            </ns:PricingQuoteOutput>
        </xsl:template>

        <xsl:template match="tem:list[tem:item/tem:field[@name='DOWNPAYMENT']]">
            <xsl:apply-templates select="tem:item/tem:field[@name='DOWNPAYMENT']" />
        </xsl:template>

        <xsl:template match="tem:field[@name='DOWNPAYMENT']">
            <xsl:variable name="pos" select="position()" />
            <ns:Campaigns>
                <ns:campaignNumber><xsl:value-of select="/tem:responseDA/tem:outputData/tem:dictionary/tem:list[tem:item/tem:field[@name='CAMPAIGNCODE']]/tem:item[position()=$pos]/tem:field"/></ns:campaignNumber>
                <ns:downPayment><xsl:value-of select="."/></ns:downPayment>
                <ns:ballonPayment><xsl:value-of select="../../../tem:list[tem:item/tem:field[@name='BALLOONPAYMENT']]/tem:item[position()=$pos]/tem:field"/></ns:ballonPayment>
            </ns:Campaigns>
        </xsl:template>
    </xsl:stylesheet>

希望能有所帮助并随时接受答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM