2016-12-15 3 views
0

私は以下のXMLを持っています。XSLTを使用したXMLからの複数のノードにわたる複数の属性によるグループ

どのように私の要素をxslt 1.0のグループ名でグループ化できますか?私は、communs_paramsアドレス、価格、および付加価値に基づいて値をグループ化する必要があります。その他のパラメータ(タイプ)different_params

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<productsGrouppe> 
<product> 
    <adressParam> 
    <parameter name="adress" > 
    <value>street 1 </value> 
    </parameter> 
    </adressParam> 
    <priceParam> 
    <parameter name="price" > 
    <value>100 EUR </value> 
    </parameter> 
    <parameter name="vat" > 
    <value> 1 </value> 
    </parameter> 
    </priceParam> 
    <deliveryParam> 
    <parameter name="type" > 
    <value> post </value> 
    </parameter> 
    </deliveryParam> 
</product> 
<product> 
    <adressParam> 
    <parameter name="adress" > 
    <value>street 2 </value> 
    </parameter> 
    </adressParam> 
    <priceParam> 
    <parameter name="price" > 
    <value>200 EUR </value> 
    </parameter> 
    <parameter name="vat" > 
    <value> 2 </value> 
    </parameter> 
    </priceParam> 
    <deliveryParam> 
    <parameter name="type" > 
    <value> E-mail </value> 
    </parameter> 
    </deliveryParam> 
</product> 
<product> 
    <adressParam> 
    <parameter name="adress" > 
    <value>street 1 </value> 
    </parameter> 
    </adressParam> 
    <priceParam> 
    <parameter name="price" > 
    <value>100 EUR </value> 
    </parameter> 
    <parameter name="vat" > 
    <value> 1 </value> 
    </parameter> 
    </priceParam> 
    <deliveryParam> 
    <parameter name="type" > 
    <value> selfcollectors </value> 
    </parameter> 
    </deliveryParam> 
</product> 
</productsGrouppe> 

期待される結果の下にグループ化されなければならない:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<productsGrouppe> 
<product> 
    <commun_params> 
    <value>street 1 </value> 
    <value>100 EUR </value> 
    <value> 1 </value> 
    </commun_params> 
    <different_params> 
    <value> post </value> 
     <value> selfcollectors </value> 
    </different_params> 
</product> 
</productsGrouppe> 
+0

Iここから始めることをお勧めします:http://www.jenitennison.com/xslt/grouping/muenchian.htmlこれを実装する実際の問題に –

+0

それは私の試みだった: – Jeeyong

答えて

0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:key name="product_adress" match="adressParam/parameter[@name='adress']/value" use="."/> 

    <xsl:variable name="priceparam_price" select="priceParam/parameter[@name='price']/value"></xsl:variable> 
    <xsl:variable name="priceparam_vat" select="priceParam/parameter[@name='vat']/value"></xsl:variable> 
    <xsl:variable name="adressParam_adress" select="adressParam/parameter[@name='adress']/value"></xsl:variable> 

    <xsl:template match="productsGrouppe"> 
     <product> 
      <xsl:apply-templates select="product/adressParam/parameter[@name='adress']/value[generate-id(.)=generate-id(key('product_adress',.)[1])]"/> 
     </product> 
    </xsl:template> 

    <xsl:template match="product"> 

      <xsl:for-each select="key('product_adress', $adressParam_adress)"> 
       <commun_params> 
        <value><xsl:value-of select="$adressParam_adress" /></value> 
        <value><xsl:value-of select="$priceparam_price" /></value> 
        <value><xsl:value-of select="$priceparam_vat" /></value> 
       </commun_params> 
      </xsl:for-each> 

    </xsl:template> 

</xsl:stylesheet> 

それが結果であった:

通り1本の街路2

関連する問題