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 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

Related Questions

Yes, this probably shouldn't bug me. But it does!! Why does XML have such
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
I have such xml: <bean id=conversionService class=org.springframework.context.support.ConversionServiceFactoryBean> <property name=converters> <list> <bean class=converters.AddressToStringConverter /> <bean
I have an xml string such as this: <s:Envelope xmlns:s=http://schemas.xmlsoap.org/soap/envelope/> <s:Body> <ExecuteResponse xmlns=http://schemas.microsoft.com/xrm/2011/Contracts/Services> <ExecuteResult
I have a class decorated with XML attributes such as [XmlAttribute(att)]. My goal is
I have a maven dependency in my pom.xml as such: <dependency> <groupId>com.foo</groupId> <artifactId>Bar</artifactId> <version>1.2.3</version>
I am parsing some XML that will have a link such as the following
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...
I have to parse a 1Gb XML file with a structure such as below
Have a JUNIT test set up as such @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ /applicationContext.xml, /applicationContext-security.xml }) @TransactionConfiguration(defaultRollback

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.