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 6007015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:37:17+00:00 2026-05-23T01:37:17+00:00

Let’s say I have an XML file that looks like this: <a id=x> <b>

  • 0

Let’s say I have an XML file that looks like this:

<a id="x">
    <b>
        <b>
            <a id="y">
                <b>
                    <c />
                </b>
            </a>
        </b>
        <c>
            <a id="z">
                <b>
                    <c />
                </b>
            </a>
        </c>
    </b>
</a>

After many hours of working, I’ve finally gotten it so that the “a”, “b”, and “c” templates recurse properly. The one probably I have left is that I need the value of a/@id to be available in b and c. But I also need to be able to reset that value when it gets to the inner a. (That is, in a#x > b > b > a#y > b > c I need the value ‘y’, but in a#x > b > b I need the value ‘x’. In other words, I need the most ancestorally-recent value of a/@id.)

The problem is complicated by the fact that the b elements can be nested an indeterminate number of times, so it’s not simply the case of doing ../../@id or something.

Since it doesn’t seem like variables or parameters would work for this, I was thinking an acceptable workaround would be to automatically carry the @id down to each child element. However, I couldn’t figure out a way to do this using xsl:attribute, as that always seems to modify the output tree, rather than the input or currently-processing tree.

Any tips?

  • 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-23T01:37:18+00:00Added an answer on May 23, 2026 at 1:37 am

    Can’t you just do ancestor::a[first()]/@id?

    <xsl:template match="a">
       ...
       <xsl:apply-templates match="*" />
    </xsl:template>
    
    <xsl:template match="b">
       <xsl:variable name="id" select="ancestor::a[first()]/@id" />
       ...
       <xsl:apply-templates match="*" />
    </xsl:template>
    
    <xsl:template match="b">
       <xsl:variable name="id" select="ancestor::a[first()]/@id" />
       ...
       <xsl:apply-templates match="*" />
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a set of relations that looks like this: relations
Let say that I have xml like this: <root> <node light=somevalue>message1</node> <node dark=somevalue>message2</node> <node>message3</node>
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that we have the above code: (require-extension defstruct) (defstruct tree height age
Let me start off by saying that this is my first time working with
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have this code: <p dataname=description> Hello this is a description. <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.