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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:54:46+00:00 2026-05-27T22:54:46+00:00

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

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

Hi,

I am not sure how to get this working with xslt. The xml file has “Envelope” elements always in even number of occurences, the reason being, the xml will indicate us success, error or warning based on pairs(first and second, third and fourth etc). The top priority is for “criticalerror” element, that is, if this element is present in the pair, the pair is considered as error, the element can occur twice as well.

The next priority goes to “milderror” element which stands for warning. The third priority goes to “success” element. Therefore only if both contains “success” in the pair, considered as success.

For the above case first pair is success, second one is an error, third one is an error, fourth one is a warning. There are two errors, one success and one warning. This will produce an xml like below. Again, error is having higher priority(occurs first in xml), warning next

<Root>
  <error></error>
  <error></error>
  <warning></warning>
  <success></success>
</Root>

Now I have a for each action with the above xml, for each paired scenarios(success, error and warning), there are three for each actions(that is how my design is ), which is an action in datapower

Coming to my success for each action, I need to get the “ineed” element from the top xml, corresponding to the success pair, which is “apple”, this can occur in either one or both, within a pair of top xml. It is same for a pair, however can occur in either one, or both.

All I have is the context loopcount variable(1 in this case), for success, which is going to iterate for all success scenario

Similary for error scenario(looping 2 times in this case), need to get the corresponding “ineed” element from top xml. Loopcount variable 1, next time loopcount variable is 2

Samething for warning scenario as well.

  • 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-27T22:54:46+00:00Added an answer on May 27, 2026 at 10:54 pm

    Here is a complete solution:

    <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:template match="/*">
         <Root>
          <xsl:apply-templates select="Envelope[position() mod 2 = 1]">
           <xsl:sort select=
             "not((.|following-sibling::Envelope[1])/criticalerror)"/>
           <xsl:sort select=
             "not((.|following-sibling::Envelope[1])/milderror)"/>
          </xsl:apply-templates>
         </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
        ]">
    
      <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)
        ]">
    
      <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 this transformation is applied on the provided XML document:

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

    the wanted, correct result is produced:

    <Root>
       <error>apple</error>
       <error>apple</error>
       <warning>apple</warning>
       <success>apple</success>
    </Root>
    

    Explanation:

    1. No <xsl:for-each> is used, only <xsl:apply-templates>.

    2. Templates are explicitly applied only on the first Envelope of each pair of Envelope elements.

    3. The order in which the result of processing the elements (in the node-list specified in the select attribute of xsl:apply-templates) is output, is specified in two xsl:sort instructions — first go errors, then warnings, then anything else (success).

    4. We use the fact that when booleans are sorted, false() precedes true().

    5. The template named getTitle is called to output the wanted string value of the first non-empty ineed element contained in the respective pair of Envelope elements.

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

Sidebar

Related Questions

map.root :controller => main, :action => index is not redirecting the main controller to
(5)Root (3)-------^--------(7) (2)---^----(5) ^-----(8) I want to add node with data 5 in this
I don't have root access on a remote box I'm working with, so I'm
root@app1:~# gem -v 1.8.10 I get 1.8.10 when I use rvm. But when I
I'm trying to get an attribute id ( fileID ) from my XML document
I have a XML file that looks like this <Licence> <Name>Test company</Name> <Version>1.1.1.1</Version> <NumberOfServer>2</NumberOfServer>
root@dicksonxavier-desktop:/home/dicksonxavier/Downloads/MySQL-python-1.2.3# python setup.py build sh: mysql_config: not found Traceback (most recent call last): File
[root@dev-test test]$ perl -e %hash=(key,1);print 1 if exists $hash{key}; exists argument is not a
header: Root, sortable: true, renderer: cat_id1, dataIndex: 'parent_id', width: 90, editor: new Ext.form.ComboBox({ typeAhead:
I need, in C# (4.0), to sign an XML (XMLDSig Envelope) using a X509Certificate

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.