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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:36:09+00:00 2026-05-27T20:36:09+00:00

As per suggestions, posting this question in a seperate thread. The question is a

  • 0

As per suggestions, posting this question in a seperate thread. The question is a continuation, to the below link

xslt-loop-count-context-value-from-top-xml

We wanted to produce the below xml as output(some changes in the outputxml). the tag, “errorsandwarnings” should be present in case atleast one error or warning is present,”allerrors” tag when atleast one error is present, “allwarnings” tag when atleast one warning is present

<Root>
  <errorsandwarnings>
    <allerrors>
      <error>apple</error>
      <error>apple</error>
    </allerrors>
    <allwarnings>
      <warning>apple</warning>
    </allwarnings>
  </errorsandwarnings>
  <success>apple</success>
</Root>
  • 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-27T20:36:09+00:00Added an answer on May 27, 2026 at 8:36 pm

    This transformation:

    <xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output omit-xml-declaration="yes" indent="yes"/>
         <xsl:strip-space elements="*"/>
    
         <xsl:variable name="vErrors" select=
         "/*/Envelope[position() mod 2 = 1]
                       [(.|following-sibling::Envelope[1])
                                              /criticalerror
                       ]"/>
    
         <xsl:variable name="vWarnings" select=
         "/*/Envelope[position() mod 2 = 1]
                       [(.|following-sibling::Envelope[1])
                                                  /milderror
                       ]"/>
    
         <xsl:variable name="vErrorsWarnings" select=
         "$vErrors | $vWarnings"/>
    
         <xsl:variable name="vSuccess" select=
            "/*/Envelope
                [position() mod 2 = 1]
                  [not((.|following-sibling::Envelope[1])
                        /*[self::criticalerror or self::milderror]
                      )
                  ]
         "/>
    
         <xsl:template match="/*">
             <Root>
               <xsl:if test="$vErrorsWarnings">
                <errorsandwarnings>
                 <xsl:apply-templates select="$vErrors"/>
                 <xsl:apply-templates select="$vWarnings"/>
                </errorsandwarnings>
               </xsl:if>
    
               <xsl:apply-templates select="$vSuccess"/>
             </Root>
         </xsl:template>
    
         <xsl:template match=
          "Envelope
            [position() mod 2 = 1
           and
             success
           and
             following-sibling::Envelope[1]/success
            ]">
    
          <success>
           <xsl:call-template name="getTitle"/>
          </success>
         </xsl:template>
    
         <xsl:template match=
          "Envelope
            [position() mod 2 = 1
           and
             (.|following-sibling::Envelope[1])/criticalerror
            ][1]">
           <allerrors>
             <xsl:apply-templates mode="error" select="$vErrors"/>
           </allerrors>
         </xsl:template>
    
    
         <xsl:template match="Envelope" mode="error">
          <error>
           <xsl:call-template name="getTitle"/>
          </error>
         </xsl:template>
    
         <xsl:template match=
          "Envelope
            [position() mod 2 = 1
           and
             (.|following-sibling::Envelope[1])/milderror
           and
             not((.|following-sibling::Envelope[1])/criticalerror)
            ][1]">
           <allwarnings>
             <xsl:apply-templates mode="warning" select="$vWarnings"/>
           </allwarnings>
         </xsl:template>
    
         <xsl:template match="Envelope" mode="warning">
          <warning>
           <xsl:call-template name="getTitle"/>
          </warning>
         </xsl:template>
    
         <xsl:template name="getTitle">
          <xsl:value-of select=
            "(.|following-sibling::Envelope[1])
                 /Header/ineed[normalize-space()]
                                               [1]
            "/>
         </xsl:template>
         <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the XML document provided in the previous question:

    <Root>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <success></success>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <success></success>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <criticalerror></criticalerror>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <success></success>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <criticalerror></criticalerror>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <criticalerror></criticalerror>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <milderror></milderror>
        </Envelope>
        <Envelope>
            <Header>
                <ineed>apple</ineed>
            </Header>
            <success></success>
        </Envelope>
    </Root>
    

    produces the wanted, correct result:

    <Root>
       <errorsandwarnings>
          <allerrors>
             <error>apple</error>
             <error>apple</error>
          </allerrors>
          <allwarnings>
             <warning>apple</warning>
          </allwarnings>
       </errorsandwarnings>
       <success>apple</success>
    </Root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, per suggestions on clarifying the intent I have restated the question. Hope this
Per this question (see comments near the bottom), I was wondering if anyone knows
I wanted to store variables per tab scope. This same question was raised already
Per this helpful article I have confirmed I have a connection pool leak in
Per a great answer from another question I have begun mounting global resources (css/js/images)
i already gone through other web game cheating question on this forum but i
I'm developing PHP on a mac. As per other suggestions, I've set the workspace
I'm currently developing a Rails app with 4 nested models (as per THIS POST
Per suggestions on SO/SF and other sites, I am using CherryPy as the WSGI
I've added UIFileSharingEnabled to the .plist. Per suggestions, I have: removed the app and

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.