简体   繁体   中英

Concate after Choose XSLT1.0 or 2.0

Still new to this forum and XSLT, already searched but could not find the correct solution.

i am trying to get the right concat after the choose, if i match the condition 208 or 906 is still get LX1234 as combination, it always ends up on the otherwise as solution. the XSLT is build in 2.0 so both solutions will work for me.

<xsl:for-each select="XXX/Envelope/PickingList/Line/Lot">
                <articleLine type="tag">
                    <articleCode>
                        <xsl:choose>
                            <xsl:when test="XXX/Envelope/GLN_Supplier =208">

                                 <xsl:value-of select="concat('AV',../ArticleCodeSupplier)"/> 
                            </xsl:when>
                            <xsl:when test="XXX/Envelope/GLN_Supplier =906">

                                <xsl:value-of select="concat('KR',../ArticleCodeSupplier)"/> 
                            </xsl:when>
                            <xsl:otherwise>
                                 <xsl:value-of select="concat('LX',../ArticleCodeSupplier)"/>

                            </xsl:otherwise>
                        </xsl:choose>
                    </articleCode>

Edit XML input, thank you for pointing that out @michael.hor257k



<?xml version='1.0' encoding='ISO-8859-1'?>
<XXX>
    <Envelope>
        <InterchangeControlReference>995566</InterchangeControlReference>
        <GLN_Supplier>906</GLN_Supplier>
        <GLN_Customer>541</GLN_Customer>
        <PickingList>
            <PickingListNumber>9</PickingListNumber>
            <PickingDate>2019-08-01</PickingDate>
            <OrderNumberSupplier>12345</OrderNumberSupplier>
            <OrderNumberCustomer>EDI Test 1</OrderNumberCustomer>
            <EarliestDeliveryDate>2019-10-09</EarliestDeliveryDate>
            <EarliestDeliveryTime>14:13:39</EarliestDeliveryTime>
            <LastDeliveryDate>2019-10-09</LastDeliveryDate>
            <LastDeliveryTime>14:13:39</LastDeliveryTime>
            <GLN_Supplier>215</GLN_Supplier>
            <GLN_WarehouseAddressSupplier>541</GLN_WarehouseAddressSupplier>
            <GLN_Customer>000</GLN_Customer>
            <GLN_DeliveryAddressCustomer>000</GLN_DeliveryAddressCustomer>
            <GLN_CarrierAddressCustomer></GLN_CarrierAddressCustomer>
            <DeliveryName>CLIENTNAME</DeliveryName>
            <DeliveryNameContactperson></DeliveryNameContactperson>
            <DeliveryTelephoneNumber></DeliveryTelephoneNumber>
            <DeliveryAddress>CLIENTADDRESS</DeliveryAddress>
            <DeliveryAddress2></DeliveryAddress2>
            <DeliveryHouseNumber>0</DeliveryHouseNumber>
            <DeliveryHouseNumberExtra></DeliveryHouseNumberExtra>
            <DeliveryPostalCode>1111 aa</DeliveryPostalCode>
            <DeliveryCity>PLACE</DeliveryCity>
            <DeliveryCountryISO>NL</DeliveryCountryISO>
            <DeliveryCustomsExcise></DeliveryCustomsExcise>
            <DeliveryMethod>DDP</DeliveryMethod>
            <DeliveryIncoterm>DDP</DeliveryIncoterm>
            <DeliveryIncotermCity></DeliveryIncotermCity>
            <Remarks_Pickinglist>REMARKS WAREHOUSE</Remarks_Pickinglist>
            <Remarks_Packinglist>REMARKS FREIGHTBILL</Remarks_Packinglist>
            <Remarks_Delivery></Remarks_Delivery>
            <CustomsExcise>true</CustomsExcise>
            <Test>false</Test>
            <Line>
                <LineNumber>1</LineNumber>
                <EAN_Article>528</EAN_Article>
                <ArticleCodeSupplier>1234</ArticleCodeSupplier>
                <ArticleCodeCustomer></ArticleCodeCustomer>
                <UnitToPick>Fles</UnitToPick>
                <ArticleDescription>VINE WINE</ArticleDescription>
                <QuantityToPick>21</QuantityToPick>
                <QuantityToPickInOrderUnit>21</QuantityToPickInOrderUnit>
                <UnitOrdered>Fles</UnitOrdered>
                <Lot>
                    <LotCode>72</LotCode>
                    <BatchCode>3</BatchCode>
                    <YearOfProduction>2017</YearOfProduction>
                    <QuantityToPick>21</QuantityToPick>
                </Lot>
            </Line>
            <Line>
                <LineNumber>2</LineNumber>
                <EAN_Article>081</EAN_Article>
                <ArticleCodeSupplier>5678</ArticleCodeSupplier>
                <ArticleCodeCustomer></ArticleCodeCustomer>
                <UnitToPick>Fles</UnitToPick>
                <ArticleDescription>CHAMPAGNE</ArticleDescription>
                <QuantityToPick>10</QuantityToPick>
                <CountryOfOriginISO>ES</CountryOfOriginISO>
                <QuantityToPickInOrderUnit>10</QuantityToPickInOrderUnit>
                <UnitOrdered>Fles</UnitOrdered>
                <Lot>
                    <LotCode>5</LotCode>
                    <BatchCode>4</BatchCode>
                    <YearOfProduction>2019</YearOfProduction>
                    <QuantityToPick>10</QuantityToPick>
                    <CountryOfOriginISO>ES</CountryOfOriginISO>
                </Lot>
            </Line>
        </PickingList>
    </Envelope>
</XXX>

The instruction:

<xsl:for-each select="XXX/Envelope/PickingList/Line/Lot">

puts you in the context of Lot . From this context, the test in:

<xsl:when test="XXX/Envelope/GLN_Supplier =208">

will return false, because the relative path XXX/Envelope/GLN_Supplier selects nothing. You will get a different result if you make the path an absolute one:

 <xsl:when test="/XXX/Envelope/GLN_Supplier =208">

Of course, it would be more efficient to do this test once outside the xsl:for-each block and make the result available in a variable - for example:

<xsl:template match="/XXX">
    <output>
        <xsl:variable name="articleCodePrefix">
            <xsl:choose>
                <xsl:when test="Envelope/GLN_Supplier=208">AV</xsl:when>
                <xsl:when test="Envelope/GLN_Supplier=906">KR</xsl:when>
                <xsl:otherwise>LX</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:for-each select="Envelope/PickingList/Line/Lot">
            <articleLine type="tag">
                <articleCode>
                    <xsl:value-of select="$articleCodePrefix"/> 
                    <xsl:value-of select="../ArticleCodeSupplier"/>
                </articleCode>
            </articleLine>
        </xsl:for-each>
    </output>
</xsl:template>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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