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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:24:53+00:00 2026-05-22T17:24:53+00:00

XML <swift> <message> <block2 type=input> <messageType>102</messageType> <receiverAddress>BKTRUS33XBRD</receiverAddress> <messagePriority>N</messagePriority> </block2> <block3> <tag> <name>32</name> <value>praveen</value> </tag>

  • 0

XML

<swift>
 <message>
     <block2 type="input">
        <messageType>102</messageType>
        <receiverAddress>BKTRUS33XBRD</receiverAddress>
        <messagePriority>N</messagePriority>     
     </block2>
     <block3>
     <tag>
     <name>32</name>
     <value>praveen</value>
     </tag>
     <tag>
     <name>42</name>
     <value>pubby</value>
     </tag>
     </block3> 
     <block4>
     <tag>
     <name>77</name>
     <value>pravz</value>
     </tag>
     <tag>
     <name>77</name>
     <value>pubbypravz</value>
     </tag>
     <tag>
     <name>99</name>
     <value>USA</value>
     </tag>
     <tag>
     <name>99</name>
     <value>UK</value>
     </tag>
     <tag>
     <name>76</name>
     <value>shanmu</value>
     </tag>
  </block4>
 </message>
</swift>

XSL

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

          <xsl:output method="text" />
           <xsl:param name="count" select="000001"></xsl:param >
            <xsl:template match="/">
             <xsl:for-each select ="swift/message">

             <xsl:variable name="newtype">
        <xsl:choose>
        <xsl:when test="block2[@type = 'input']">

     <xsl:value-of  select=" concat('O', block2/messageType,block2/messagePriority )"/>,<xsl:text/>
            </xsl:when>

            <xsl:when test="block2[@type = 'output']">
     <xsl:value-of  select=" concat('I', block2/messageType,block2/messagePriority )"/>,<xsl:text/>
        </xsl:when>
           </xsl:choose>
            </xsl:variable>

    <xsl:for-each select ="/swift/message/block3/tag[name='32']">
    <xsl:variable name = "first-val" select="value"/>

    <xsl:for-each select ="/swift/message/block4/tag[name='77']">
    <xsl:value-of select="concat($count,',',$first-val, ',',value)"/>

    <xsl:text>
        </xsl:text>
         </xsl:for-each>
       </xsl:for-each>
    </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

i need to copy the data of which were i have declared name of “newtype” required the data should print in place of this bellow line

  <xsl:value-of select="concat($newtype,',',$first-val, ',',value)"/>

but above which was showing wrong because variable name was declared out of the scope so can any modify make me to reach that ouput please

the above i have hot coded this value 000001 but needed increment for every record

Expected Output

O102N,000001,praveen,pravz,USA

O102N,000002, praveen,pubbypravz,UK

  • 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-22T17:24:54+00:00Added an answer on May 22, 2026 at 5:24 pm

    Can you show me your input xml and desired output xml?

    I kind of cringe a little when I see a foreach in xsl – it’s a template language, and rarely needs foreach…

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE stylesheet [
        <!ENTITY comma "<xsl:text>,</xsl:text>">
        <!ENTITY cr "<xsl:text>
    </xsl:text>">
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    >
        <xsl:output method="text" indent="no" />
        <xsl:template match="/">
            <xsl:apply-templates select="/swift/message/block4/tag [name='77']"/>
        </xsl:template>
    
        <xsl:template match="message/block4/tag [name='77']">
            <xsl:apply-templates select="../../block2/@type"/>
            <xsl:value-of select="../../block2/messageType"/>
            <xsl:value-of select="../../block2/messagePriority"/>&comma;
            <xsl:number format="000001"/>&comma;
            <xsl:value-of select="../../block3/tag [name='32']/value"/>&comma;
            <xsl:value-of select="value"/>&cr;
        </xsl:template>
    
        <xsl:template match="@type[.='input']">O</xsl:template>
    
        <xsl:template match="@type[.='output']">I</xsl:template>
    
        <xsl:template match="text()"/>
    
    </xsl:stylesheet>
    

    You need one row for each block4 name. So apply a template for that block4/tag [name=’77’]

    Then – for every one of those, select the parent elements that you need.

    xsl:number will count the number of times it selected.

    The ENTITY items are there to control whitespace – otherwise the formatting is crap.

    No need for a foreach. Hope this helps

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

Sidebar

Related Questions

XML sample ( original link ): <records> <record index=1> <property name=Username>Sven</property> <property name=Domain>infinity2</property> <property
XML seems to be the language of the day, but it's not type safe
XML Categary tag is same data For me i got twice in table View
having a xml with same tag names but for that tag names values were
I have added following lines at start of %PRPOGRA~%\Notepad++\plugin\APIs\php.xml <KeyWord name=$_GET></KeyWord> <KeyWord name=$_POST></KeyWord> <KeyWord
XML Schema specifies occurrence indicators (maxOccurrence, minOccurrence). Is there a best practice in which
XML: <A><B></B></A> or <A></A> I want to get all A nodes that do not
xml.etree.ElementTree.parse is choking on my xhtml file. I saw somewhere that lxml can handle
XML is cool in flex, but I have an annoying problem to solve, caused
The XML Schema Part 2 specifies that an instance of a datatype that is

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.