2014-08-27 68 views
0

我想轉換下面的輸入XML基於限定符的分組,但它不工作,並沒有給我預期的輸出。轉換爲多等

下面是必須翻譯的輸入XML。

<document> 
<item> 
    <gtin>1000909090</gtin> 
    <attrGroupMany name="foodAndBevPreparationInfo"> 
     <row> 
      <attr name="preparationType">BOILING</attr> 
      <attrQualMany name="preparationInstructions"> 
       <value qual="en">Prep 8</value> 
       <value qual="en">Prep 9</value> 
       <value qual="ar">Test</value> 
      </attrQualMany> 
     </row> 
    </attrGroupMany> 
</item> 
</document> 

我正在使用但沒有給我預期輸出的XSLT。

XSLT:

<xsl:stylesheet 
version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output indent="yes"/> 

<xsl:key name="prepmvl" match="preparationInstructions" use="concat(generate-id(..), '|', @qual)" /> 

<xsl:template match="document"> 
    <CatalogItem> 
<RelationshipData> 
     <xsl:for-each select="item/attrGroupMany[@name ='foodAndBevPreparationInfo']/row"> 
      <Relationship> 
        <RelationType>Item_Master_Food_And_Bev_Prep_MVL</RelationType>     
       <RelatedItems count="{count(attrQualMany[@name='preparationInstructions']/value[generate-id() = generate-id(key('prepmvl', concat(generate-id(..), '|', @qual))[1])])}">       
       <xsl:apply-templates select="attrQualMany[@name='preparationInstructions']/value[generate-id() = generate-id(key('prepmvl', concat(generate-id(..), '|', @qual))[1])]"/> 
       </RelatedItems> 
      </Relationship> 
     </xsl:for-each> 
    </RelationshipData> 
    </CatalogItem> 

</xsl:template> 

<xsl:template match="preparationInstructions">    
    <RelatedItem1 referenceKey="{concat('Food_And_Bev_Prep_MVL','-',ancestor::item/gtin,'-',attr[@name='preparationType'],'-',@qual)}"/> 
</xsl:template> 

</xsl:stylesheet> 

和預期輸出應該是

<?xml version="1.0" encoding="UTF-8"?> 
<CatalogItem> 
<RelationshipData> 
    <Relationship> 
     <RelationType>Item_Master_Food_And_Bev_Prep_MVL</RelationType> 
     <RelatedItems count="2"> 
      <RelatedItem1 referenceKey="Food_And_Bev_Prep_MVL-1000909090-BOILING-en" /> 
      <RelatedItem1 referenceKey="Food_And_Bev_Prep_MVL-1000909090-BOILING-ar" />    
     </RelatedItems> 
    </Relationship> 
</RelationshipData> 
</CatalogItem> 

回答

1

您需要更改

<xsl:key name="prepmvl" match="preparationInstructions" use="concat(generate-id(..), '|', @qual)" /> 

<xsl:key name="prepmvl" match="value" use="concat(generate-id(..), '|', @qual)" /> 

<xsl:template match="preparationInstructions">    
    <RelatedItem1 referenceKey="{concat('Food_And_Bev_Prep_MVL','-',ancestor::item/gtin,'-',attr[@name='preparationType'],'-',@qual)}"/> 
</xsl:template> 

<xsl:template match="value">    
    <RelatedItem1 referenceKey="{concat('Food_And_Bev_Prep_MVL','-',ancestor::item/gtin,'-',../preceding-sibling::attr[@name='preparationType'],'-',@qual)}"/> 
</xsl:template> 
+0

謝謝..它的工作 – Victor 2014-08-27 08:52:35

+1

如果您發現這個答案是有用的。請在左邊的複選標記上打勾(使其顯示爲綠色)。這樣其他用戶可以知道這是被接受的答案。請在您的所有問題中也這樣做。儘管如此,每個問題只能接受1個答案。 – 2014-08-27 08:55:42