PurpleSkittles
PurpleSkittles

Reputation: 1

Muenchian Method not working in Altova XMLSpy

I'm trying to group the container_ids in my input xml by the store number using the Muenchian method by it is not giving me the desired output.

Here is my input file:

    <D856s>
    <D856>
        <container_id>1234</container_id>
        <trip_no>15</trip_no>
        <store>5</store>
        <description>description1</description>
    </D856>
    <D856>
        <container_id>9956</container_id>
        <trip_no>18</trip_no>
        <store>4</store>
        <description>description2</description>
    </D856>
    <D856>
        <container_id>5566</container_id>
        <trip_no>20</trip_no>
        <store>4</store>
        <description>description3</description>
    </D856>
    <D856>
        <container_id>2233</container_id>
        <trip_no>19</trip_no>
        <store>5</store>
        <description>description4</description>
    </D856>
    <D856>
        <container_id>1122</container_id>
        <trip_no>12</trip_no>
        <store>2</store>
        <description>description5</description>
    </D856>
    </D856s>

Here is the code I wrote in XSLT 1.0:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:apply-templates select="D856s"/>
    </xsl:template>
    <xsl:key name="groupByStore" use="D856" match="store"/>
    <xsl:template match="D856s">
        <xsl:for-each select="D856[count(. | key('groupByStore', store)[1]) = 1]">
            <xsl:sort select="store"/>
            <StoreNum>
                <xsl:value-of select="store"/>
            </StoreNum>
            <barcode>
                <xsl:for-each select="key('groupByStore', store)">
                    <xsl:sort select="container_id"/>
                    <xsl:value-of select="container_id"/>
                </xsl:for-each>
            </barcode>
        </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

I'm new to this, can someone help me understand why each unique storenum just isn't appearing once in my output and why aren't the barcode values being mapped from the container_id?

Thanks in advance.

Upvotes: 0

Views: 35

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116959

Your key definition is wrong. Instead of:

<xsl:key name="groupByStore" use="D856" match="store"/>

it should be:

<xsl:key name="groupByStore" match="D856" use="store"/>

Upvotes: 0

Related Questions