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

  • SEARCH
  • Home
  • 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 6975521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:22:44+00:00 2026-05-27T17:22:44+00:00

I am trying to render some data from a large XML using XSLT. The

  • 0

I am trying to render some data from a large XML using XSLT. The XML data is actually kind of graph data and not hierarchical. and elements are related to each other and as such may end up havin a circular reference (the relation types are different however).

I am trying to traverse through the relationships from one element and visiting each related element and so on. In this way, at times I reach one element that I have already traversed. In such a case, I should stop traversing further as otherwise I shall be running in a cycle.

My problem is that I am not able to store the list of elements that I have already traversed and make a look up everytime I start traversing an element, so that I can stop traversing if the element is in the lookup.

Simply said, I wanted to keep the elements in a lookup table and add each element to it as I traverse.

Is there some solution for this?

  • 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-27T17:22:45+00:00Added an answer on May 27, 2026 at 5:22 pm

    A recursive template can pass itself parameters that hold a node set of “previously” processed nodes and a queue of nodes to be processed. This is a functional programming equivalent of modifying state variables.

    Sample input:

    <graph startNode="a">
        <graphNode id="a">
            <edge target="b" />
            <edge target="c" />
        </graphNode>
        <graphNode id="b">
            <edge target="c" />
        </graphNode>
        <graphNode id="c">
            <edge target="d" />
        </graphNode>
        <graphNode id="d">
            <edge target="a" />
            <edge target="b" />
        </graphNode>
    </graph>
    

    XSL 2.0 stylesheet:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="2.0">
    
        <xsl:output method="xml" indent="yes"/>
    
        <xsl:key name="graphNodeByID" match="graphNode" use="@id" />
    
        <xsl:template match="/graph">
            <results>
                <xsl:apply-templates select="key('graphNodeByID', @startNode)"
                         mode="process"/>            
            </results>
        </xsl:template>
    
        <xsl:template match="graphNode" mode="process">
            <xsl:param name="already-processed" select="/.." />
            <xsl:param name="queue" select="/.." />
    
            <!-- do stuff with context node ... -->
            <processing node="{@id}" />
    
            <!-- Add connected nodes to queue, excluding those already processed. -->
            <xsl:variable name="new-queue"
                  select="($queue | key('graphNodeByID', edge/@target))
                            except ($already-processed | .)" />
    
            <!-- recur on next node in queue. -->
            <xsl:apply-templates select="$new-queue[1]" mode="process">
                <xsl:with-param name="already-processed"
                                select="$already-processed | ." />
                <xsl:with-param name="queue" select="$new-queue" />
            </xsl:apply-templates>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Output (tested):

    <results>
       <processing node="a"/>
       <processing node="b"/>
       <processing node="c"/>
       <processing node="d"/>
    </results>
    

    As specified, no node is processed twice, even though the graph contains cycles.

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

Sidebar

Related Questions

I am using ColdFusion (openBlueDragon) to insert the data from a large (200MB) xml
I am trying to render some old level data using the glDrawRangeElements() command. My
I am trying to come up with the best way to render some hierarchical
I am trying to render a complex XML document as webpage(FF only) using a
I am trying to use the HTML Agility pack to scrape some data from
I'm trying to pull some binary data from a database and write them to
I've got some code which draws data from an xml file but it seems
I am trying to read some data from html forms and insert it into
I am trying to get some data from a web server. When I go
I'm trying to pass some data from one activity to a new one but

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.