Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3391800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:50:41+00:00 2026-05-18T03:50:41+00:00

Is there a way to avoid processing of already processed nodes? Input XML <?xml

  • 0

Is there a way to avoid processing of already processed nodes?

Input XML

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <node1>node1.1</node1>
    <node2>node2.1</node2>
    <node2>node2.2</node2>
    <node1>node1.2</node1>
</root>

XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="root">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="node1">
        [Node1]:<xsl:value-of select="."></xsl:value-of>
        <xsl:apply-templates select="following-sibling::node2"/>
        [End node1]
    </xsl:template>

    <xsl:template match="node2">
            [Node2]:<xsl:value-of select="."></xsl:value-of>
    </xsl:template>

</xsl:stylesheet>

Output

<?xml version="1.0" encoding="UTF-8"?>

        [Node1]:node1.1
            [Node2]:node2.1
            [Node2]:node2.2
        [End node1]

            [Node2]:node2.1

            [Node2]:node2.2

        [Node1]:node1.2
        [End node1]

As you can see template <xsl:template match="node2"> is applied twice for every node2 element – one time from node1 template and second time when XSLT processor is transforming node2 element.

Is there any solution to avoid applying of xsl:template match="node2" second time?
I need to stop processing of node2 when I just processed it in template for node1.

Important
This example is just an emulation of more complex use case.
This means that we have additonal limitation – we can’t modify template for root element processing.

I want to know if there is any way to stop processing of elements or move processing to some other elements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:50:42+00:00Added an answer on May 18, 2026 at 3:50 am

    You can use mode to name the template to use.

    You can create an empty catch-all node that will output nothing, taking care of apply-templates calls that have no select.

    The following stylesheet outputs what you need:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
        <xsl:template match="root">
            <xsl:apply-templates/>
        </xsl:template>
    
        <xsl:template match="node1">
            [Node1]:<xsl:value-of select="."></xsl:value-of>
            <xsl:apply-templates select="following-sibling::node2" mode="fromNode1"/>
            [End node1]
        </xsl:template>
    
        <xsl:template match="node2" mode="fromNode1">
                [Node2]:<xsl:value-of select="."></xsl:value-of>
        </xsl:template>
    
        <xsl:template match="node2"></xsl:template>
    </xsl:stylesheet>
    

    Note the empty modeless template at the end, and the added mode attribute on the template and the calling apply-templates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way to avoid dealing with text encoding problems?
Is there a way to avoid row deletion on an specific table using constrains?
Is there a way to avoid postbacks with gridview every time a row is
I'm hoping there's a way to avoid custom configuration files if an application runs
Is there any way to down-format a Subversion repository to avoid messages like this:
Is there some way I can define String[int] to avoid using String.CharAt(int) ?
Is there way in next piece of code to only get the first record?
is there way thats i can preselect an item when the page loads or
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there any way to check whether a file is locked without using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.