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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:39:11+00:00 2026-05-11T08:39:11+00:00

I have such xml: <A1> <B1> <C1> <C2> <C3> </B1> <B2> <C4> <C5> <C6>

  • 0

I have such xml:

<A1>   <B1>     <C1>     <C2>     <C3>   </B1>   <B2>     <C4>     <C5>     <C6>   </B2> </A1> <A2>   <B3>     <C7>     <C8>     <C9>   </B3>   <B4>     <C10>     <C11>     <C12>   </B4> </A2> 

I need to transform it to table with nested rows:

<table border='yes'> <tr>   <td>A1</td>   <td>B1</td>   <td>C1</td> </tr> <tr>   <td></td>   <td></td>   <td>C2</td> </tr> <tr>  <td></td>  <td></td>  <td>C3</td> </tr> <tr>  <td></td>  <td>B2</td>  <td>C3</td> </tr> <tr>  <td></td>  <td></td>  <td>C4</td> </tr> 

A and B appear only if they are new (not repeating in every row);

I’m trying to use position()

<xsl:template match='c'>  <tr>   <td>    <xsl:if test='IT IS THE FIRST C IN A'>      <xsl:value-of select='ancestor::A'/>    </xsl:if>   </td>   <td>    <xsl:if test='position(1)'>    <xsl:value-of select='parent'/>    </xsl:if>   </td>   <td>     <xsl:value-of select='.'/>   </td>  </tr> </xsl:template> 

It seems that we should emulate position() for ancestor. Is there a general solution for any number of nested rows?

  • 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. 2026-05-11T08:39:11+00:00Added an answer on May 11, 2026 at 8:39 am

    You perhaps need something like the following (if I understood your question correctly):

    <xsl:template match='C'>  <tr>   <td>    <xsl:if test='generate-id(ancestor::A/descendant::C[1]) = generate-id(.)'>      <xsl:value-of select='ancestor::A'/>    </xsl:if>   </td>   <td>    <xsl:if test='not(previous-sibling::C)'>      <xsl:value-of select='..'/>    </xsl:if>   </td>   <td>     <xsl:value-of select='.'/>   </td>  </tr> </xsl:template>  <xsl:template match='/'>   <xsl:apply-templates select='descendant::C'/> </xsl:template> 

    Edit: you may also use

    not(previous-sibling::C) and not(../previous-sibling::B) 

    as the first test (instead of using generate-id()).

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can't remove items from a collection whilst you are… May 11, 2026 at 11:05 am
  • added an answer International Components for Unicode (ICU) does have the solutions you… May 11, 2026 at 11:05 am
  • added an answer Encapsulation. In the second instance you've just defined a variable,… May 11, 2026 at 11:05 am

Related Questions

Greetings! If I have XML such as this: <Root> <AlphaSection> . . . </AlphaSection>
In Flex, I have an xml document such as the following: var xml:XML =
For example I have such query: Query q = sess.createQuery(from Cat cat); List cats
I have IIS6 configured such that browsing to http://localhost:8082/Reports gets me the reporting services
I have a IBAction such as: - (IBAction)showPicker:(id)sender; How can I get the name
If I have a method such as: private function testMethod(param:string):void { // Get the
If I have a method such as: public void MyMethod(int arg1, string arg2) How
If I have class names such as left, right, clear and xhtml like <a
Let's say I have a drive such as C:\ , and I want to
I have a class hierarchy as such: +-- VirtualNode | INode --+ +-- SiteNode

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.