Conversion for multiqual



我正试图根据限定符的分组来转换以下输入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>

您需要更改

<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>

相关内容

  • 没有找到相关文章

最新更新