You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSLT 1.0技术需求:按SKU合并显示包裹编号组合的实现问询

XSLT 1.0技术需求:按SKU合并显示包裹编号组合的实现问询

Hey there, from what I can tell, you're working with an XSLT 1.0 stylesheet that generates a table showing package details (like carton barcodes, inner counts, and SKU numbers) but right now each individual carton gets its own row—even if multiple cartons belong to the same SKU. Your goal is to group rows by the same SKU (item_no), combine related carton barcode values into a combined range/list, and display each grouped SKU as a single row in your table, right?

First, let's share the partial XSLT code you provided (formatted for readability):

<xsl:for-each select="packinglist_d"> 
    <xsl:variable name="preCarton" select="./preceding-sibling::*[1]/@barcode_start" /> 
    <xsl:variable name="curCarton" select="@barcode_start" /> 
    <xsl:variable name="preItemNo" select="./preceding-sibling::*[1]/@item_no" /> 
    <xsl:variable name="curItemNo" select="@item_no" /> 
    <xsl:variable name="pl_no_inners" select="@no_inners" /> 
    <xsl:variable name="pl_startCode" select="@barcode_start" /> 
    <xsl:choose> 
        <xsl:when test="$pl_startCode != '' and $p...

Since XSLT 1.0 doesn't have native grouping functions like XSLT 2.0+, we'll use the Muenchian Grouping method to achieve your desired output. Here's a step-by-step approach to modify your code:

Step 1: Define a grouping key

First, add a key at the top of your stylesheet to group all packinglist_d elements by their item_no attribute:

<xsl:key name="sku-group" match="packinglist_d" use="@item_no" />

Step 2: Iterate over unique SKUs instead of all cartons

Replace your existing <xsl:for-each select="packinglist_d"> with a loop that only processes the first occurrence of each unique SKU:

<xsl:for-each select="packinglist_d[generate-id() = generate-id(key('sku-group', @item_no)[1])]">
    <!-- Get all cartons in this SKU group -->
    <xsl:variable name="current-sku-cartons" select="key('sku-group', @item_no)" />
    
    <!-- Aggregate data for the group -->
    <xsl:variable name="total-inners" select="sum($current-sku-cartons/@no_inners)" />
    <!-- For barcodes: you can collect them as a comma-separated list, or create ranges if consecutive -->
    
    <tr>
        <td><xsl:value-of select="@item_no" /></td>
        <td>
            <!-- Example: Comma-separated barcodes -->
            <xsl:for-each select="$current-sku-cartons">
                <xsl:value-of select="@barcode_start" />
                <xsl:if test="position() != last()">, </xsl:if>
            </xsl:for-each>
        </td>
        <td><xsl:value-of select="$total-inners" /></td>
        <!-- Add other columns as needed -->
    </tr>
</xsl:for-each>

Step 3: Optional: Create consecutive barcode ranges

If your barcode_start values are sequential numbers and you want to display them as ranges (e.g., "1001-1003" instead of "1001,1002,1003"), you'll need an additional template to handle that logic. Let me know if you'd like help building that part!

Let me know if you need to adjust this to match the exact structure of your input XML or the desired table layout—happy to refine this further.

备注:内容来源于stack exchange,提问作者bsr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 07:48:05