how to enable streaming for the below code in the XSLT3.0, because the input payload can be more than 80MB and we are observing performance issues

Problem
The current issue is that with below XSLT code, when the input payload is large for example 80MB, the input payload is getting loaded into memory and because of which its consuming the memory and causing performance issue. So is there any way to handle this issue in XSLT3.0?

If we use Streaming will it resolve the issue?

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

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    
  
    <xsl:template match="/">
        <TOBRequest>
            
            <xsl:apply-templates select="TOBRequest/MessageHeader"/>
            <TOBRequest>
                <xsl:for-each select="TOBRequest/TOB">
                    <xsl:variable name="PEG" select="SAData/PEGroup"/>
                    
                    <!-- Apply templates, skipping few segments -->
                    <xsl:apply-templates select="@* | node()[not(name() = 'Item' or name() = 'CDE'/>

                    <xsl:for-each select="Item">
                        <Item>
                            <xsl:apply-templates select="@* | node()"/>
                            <xsl:variable name="ItemID" select="ID"/>
                            <xsl:variable name="Category" select="CategoryCode"/>
                            
                            <xsl:for-each select="../Item[HRelationship/ParentItemID = $ItemID]">
                                <xsl:choose>
                                    <xsl:when test="$Category = 'ABC' and not(contains($PEG, 'XYZ'))">
                                        <SubItem>
                                            <xsl:apply-templates select="@* | node()"/>
                                        </SubItem>
                                    </xsl:when>
                                    <xsl:when test="contains($PEG, 'XYZ')">
                                        <SubItem>
                                            <xsl:apply-templates select="@* | node()"/>
                                        </SubItem>
                                    </xsl:when>
                                </xsl:choose>
                            </xsl:for-each>
                        </Item>
                    </xsl:for-each>
                </xsl:for-each>
            </TransportationOrderBooking>
        </n0:TransportationOrderBookingRequest>
    </xsl:template>

    <!-- Template for copying elements -->
    <xsl:template match="*">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <!-- Template for copying attributes -->
    <xsl:template match="@*">
        <xsl:copy/>
    </xsl:template>

</xsl:stylesheet>

Your XSLT code isn’t well-formed so it’s hard for me to verify. The code isn’t streamable as written, because you visit the children/descendants of TOBRequest/TOB several times – each of the three instructions

<xsl:variable name="PEG" select="SAData/PEGroup"/>
<xsl:apply-templates select="@* | node()[...]"/>
<xsl:for-each select="Item"> 

does a downward selection. A further problem is

<xsl:apply-templates select="TOBRequest/MessageHeader"/>

The typical solution would be (a) if the TOB elements are of manageable size, do <xsl:for-each select="copy-of(TOBRequest/TOB)"> so that each TOB is constructed as an in-memory subtree and the processing within each TOB isn’t streamed, and (b) handle the MessageHeader elements in the same loop as the TOB elements, so it becomes:

<xsl:for-each select="copy-of(TOBRequest/*)">
  <xsl:if test="self::MessageHeader">...</xsl:if>

It would be easier to help you with the rewrite if you supplied working XSLT code and a specimen document.

2

below is the formatted.

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <TOBRequest>
            <xsl:apply-templates select="TOBRequest/MessageHeader"/>
            <TOB>
                <xsl:for-each select="TOBRequest/TOB">
                    <xsl:variable name="PEG" select="SAData/PEGroup"/>
                    <!-- Apply templates, skipping 'Item' and 'ShippingTypeCode' -->
                    <xsl:apply-templates select="@* | node()[not(name() = 'Item' or name() = 'SParty')]"/>
                    <xsl:for-each select="Item">
                        <Item>
                            <xsl:apply-templates select="@* | node()"/>
                            <xsl:variable name="ItemID" select="ID"/>
                            <xsl:variable name="Category" select="CategoryCode"/>
                            <xsl:for-each select="../Item[HRelationship/ParentItemID = $ItemID]">
                                <xsl:choose>
                                    <xsl:when test="$Category = 'PKG' and not(contains($PEG, 'STO'))">
                                        <SubItem>
                                            <xsl:apply-templates select="@* | node()"/>
                                        </SubItem>
                                    </xsl:when>
                                    <xsl:when test="contains($PEG, 'STO')">
                                        <SubItem>
                                            <xsl:apply-templates select="@* | node()"/>
                                        </SubItem>
                                    </xsl:when>
                                </xsl:choose>
                            </xsl:for-each>
                        </Item>
                    </xsl:for-each>
                </xsl:for-each>
            </TOB>
        </TOBRequest>
    </xsl:template>
    <!-- Template for copying elements -->
    <xsl:template match="*">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    <!-- Template for copying attributes -->
    <xsl:template match="@*">
        <xsl:copy/>
    </xsl:template>
</xsl:stylesheet>

I can’t make a suggestion for streaming without seeing the input and the wanted result but in terms of performance with a non-streaming approach I think you can use a key for

                        <xsl:variable name="ItemID" select="ID"/>
                        <xsl:variable name="Category" select="CategoryCode"/>
                        <xsl:for-each select="../Item[HRelationship/ParentItemID = $ItemID]">

i.e. by declaring a top-level

<xsl:key name="parent" match="Item" use="HRelationship/ParentItemID">

and then rewriting the three lines as

                        <xsl:variable name="ItemID" select="ID"/>
                        <xsl:variable name="Category" select="CategoryCode"/>
                        <xsl:for-each select="key('parent', $ItemID)">

That hopefully improves performance with non-streaming code.

I would also suggest to rewrite <xsl:apply-templates select="@* | node()[not(name() = 'Item' or name() = 'CDE'/> as <xsl:apply-templates select="@*, node() except (Item, CDE)"/>.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật