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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:49:23+00:00 2026-06-07T10:49:23+00:00

For this xml: <G> <P> <A> <b>value b</b> <c>value c</c> </A> <A> <b>value b2</b>

  • 0

For this xml:

 <G>
        <P>
            <A>
                <b>value b</b>
                <c>value c</c>
            </A>
            <A>
                <b>value b2</b>
                <c>value c2</c>
            </A>
            <D>value ew</D>
        <D>value e2</D>     
            <E>value f</E>
        </P>
        <P>
            <A>
                <b>value bx</b>
                <c>value cx</c>
            </A>
            <A>
                <b>value b2x</b>
                <c>value c2x</c>
            </A>
             <D>value exw</D>
        <D>value ex2</D>

         <D>value ex2</D>
            <E>value fx</E>
        </P>
    </G>

The tags like A and D can occur multiple times , the original xml on which I am working has large number of tags and many of them have multiple occurences.
I have to genetrate output as :
value b     value c     value ew     value f
value b     value c     value e2     value f
value b2     value c2     value ew     value f
value b2     value c2     value e2     value f
value bx     value cx     value exw     value fx
value bx     value cx     value ex2     value fx
value bx     value cx     value ex3     value fx
value b2x     value c2x     value exw     value fx
value b2x     value c2x     value ex2     value fx
value b2x     value c2x     value ex3     value fx

This xslt generates correct output if A tag has multiple occurence ,but when other tags like D in above xml repeat this does not work.

<xsl:for-each select="//A">
    <xsl:value-of select="b"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="c"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="ancestor::P/D"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="ancestor::P/E"/>
    <xsl:text>  
</xsl:text>
</xsl:for-each>

Please suggest correct xslt

  • 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-06-07T10:49:25+00:00Added an answer on June 7, 2026 at 10:49 am

    I think this can be achieved by using repeated calls to templates. First you have a template to match A but instead of outputting the b and c elements, you pass them as parameters to a template that matches the D elemenet

    <xsl:template match="A">
      <xsl:apply-templates select="following-sibling::D">
         <xsl:with-param name="prefix">
            <xsl:value-of select="b"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="c"/>
         </xsl:with-param>
      </xsl:apply-templates>
    </xsl:template>
    

    And then, within the the template that matches the D element, you concatenate the prefix with the value of D, and pass it to a template that matches the E element.

    <xsl:template match="D">
      <xsl:param name="prefix"/>
      <xsl:apply-templates select="following-sibling::E">
         <xsl:with-param name="prefix">
            <xsl:value-of select="$prefix"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="."/>
         </xsl:with-param>
      </xsl:apply-templates>
    </xsl:template>
    

    And then the template that matches the E element can output the whole string. Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="text" indent="yes"/>
    
       <xsl:template match="/">
          <xsl:apply-templates select="//A"/>
       </xsl:template>
    
       <xsl:template match="A">
          <xsl:apply-templates select="following-sibling::D">
             <xsl:with-param name="prefix">
                <xsl:value-of select="b"/>
                <xsl:text>,</xsl:text>
                <xsl:value-of select="c"/>
             </xsl:with-param>
          </xsl:apply-templates>
       </xsl:template>
    
       <xsl:template match="D">
          <xsl:param name="prefix"/>
          <xsl:apply-templates select="following-sibling::E">
             <xsl:with-param name="prefix">
                <xsl:value-of select="$prefix"/>
                <xsl:text>,</xsl:text>
                <xsl:value-of select="."/>
             </xsl:with-param>
          </xsl:apply-templates>
       </xsl:template>
    
       <xsl:template match="E">
          <xsl:param name="prefix"/>
          <xsl:value-of select="$prefix"/>
          <xsl:text>,</xsl:text>
          <xsl:value-of select="."/>
          <xsl:value-of select="'&#13;'"/>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your XML sample, the following is output

    value b,value c,value ew,value f
    value b,value c,value e2,value f
    value b2,value c2,value ew,value f
    value b2,value c2,value e2,value f
    value bx,value cx,value exw,value fx
    value bx,value cx,value ex2,value fx
    value bx,value cx,value ex2,value fx
    value b2x,value c2x,value exw,value fx
    value b2x,value c2x,value ex2,value fx
    value b2x,value c2x,value ex2,value fx
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have this xml from which I am trying to grab the value in
given an xml string like this: <some><nested><xml>value</xml></nested></some> what's the best option (using ruby) to
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I've a XML structure like this: <root> <element> <name>Foo</name> <subelement> <key>1.1</key> <value>Lorem ipsum</value> </subelement>
How can i extract key value pairs from this xml example using linq: <foo>
I have a stored proc that takes an input of xml value like this:
I have an XML value and an XPath query like this: XML: <Firms> <Firm
I have a table td like below. if i use this.xml the below value
For example i have this xml. I need to get value of parameter val

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.