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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:40:19+00:00 2026-06-18T07:40:19+00:00

I have a requirement where i have to convert using xslt, known tags to

  • 0

I have a requirement where i have to convert using xslt, known tags to be replaced, but for any non-identified tags should be put inside a property bag (like in c#) kind of mode. For example. I want to convert the below XML:

<Envelope>
    <body>
        <MyOperation_reply_data>
            <operation_name>1211</operation_name>
            <operation_short_desc>SCAMA</operation_short_desc>
            <operation_long_desc>C4 SCAM PIECE PART ASSEMBLY
            </operation_long_desc>
            <primary_units>UNITS</primary_units>
            <firstAttribute>123</firstAttribute>
            <sampleone>554</sampleone>
            <area>newarea</area>
            <group>samplegroup</group>
            <whatever>uuu</whatever>
        </MyOperation_reply_data>
    </body>
</Envelope>

To this format:

<Envelope>
<Body>
    <OperationInfo OperationName="MyOperation">
        <OperationData>
            <Operation>MyOperation</Operation>
            <ShortDescription>MyDescription</ShortDescription>
            <LongDescription>MyLongDescription</LongDescription>
            <PrimaryUnits>UNITS</PrimaryUnits>
            <Attributes>
                <Attribute Name="firstAttribute" Value="123" />
                <Attribute Name="sampleone" Value="554" />
                <Attribute Name="area" Value="newarea" />
                <Attribute Name="group" Value="samplegroup" />
                <Attribute Name="whatever" Value="uuu" />
            </Attributes>
        </OperationData>
    </OperationInfo>
</Body>

As you could see only the operation, operation long/shortdescription and primaryunits are the recognized tags. anything else i would want to put it in the Attributes list like above. The “other” tags list could grow – so the idea is to put all those other tags into this property bag kind of mode.

the challenge I have is that i am unable to do for-each or identify the “other” tags. I tried selected not(self:: with or statements but didn’t help much.

  • 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-18T07:40:20+00:00Added an answer on June 18, 2026 at 7:40 am

    In XSLT 1.0 you can use xsl:key to create a “white list” of elements.

    XML Input

    <Envelope>
        <body>
            <MyOperation_reply_data>
                <operation_name>1211</operation_name>
                <operation_short_desc>SCAMA</operation_short_desc>
                <operation_long_desc>C4 SCAM PIECE PART ASSEMBLY</operation_long_desc>
                <primary_units>UNITS</primary_units>
                <firstAttribute>123</firstAttribute>
                <sampleone>554</sampleone>
                <area>newarea</area>
                <group>samplegroup</group>
                <whatever>uuu</whatever>
            </MyOperation_reply_data>
        </body>
    </Envelope>
    

    XSLT 1.0

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:key name="whiteList" match="*[self::primary_units or 
                                           self::operation_name or
                                           self::operation_short_desc or
                                           self::operation_long_desc]" use="name()"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="body">
            <Body>
                <xsl:apply-templates select="@*|node()"/>
            </Body>
        </xsl:template>
    
        <xsl:template match="MyOperation_reply_data">
            <OperationInfo OperationName="{operation_name}">
                <OperationData>
                    <xsl:apply-templates select="*[key('whiteList',name())]"/>
                    <Attributes>
                        <xsl:apply-templates select="*[not(key('whiteList',name()))]"/>                 
                    </Attributes>
                </OperationData>
            </OperationInfo>
        </xsl:template>
    
        <xsl:template match="operation_name">
            <Operation><xsl:apply-templates/></Operation>
        </xsl:template>
    
        <xsl:template match="operation_short_desc">
            <ShortDescription><xsl:apply-templates/></ShortDescription>
        </xsl:template>
    
        <xsl:template match="operation_long_desc">
            <LongDescription><xsl:apply-templates/></LongDescription>
        </xsl:template>
    
        <xsl:template match="primary_units">
            <PrimaryUnits><xsl:apply-templates/></PrimaryUnits>
        </xsl:template>
    
        <xsl:template match="MyOperation_reply_data/*[not(key('whiteList',name()))]">
            <Attribute name="{name()}" value="{.}"/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    XML Output

    <Envelope>
       <Body>
          <OperationInfo OperationName="1211">
             <OperationData>
                <Operation>1211</Operation>
                <ShortDescription>SCAMA</ShortDescription>
                <LongDescription>C4 SCAM PIECE PART ASSEMBLY</LongDescription>
                <PrimaryUnits>UNITS</PrimaryUnits>
                <Attributes>
                   <Attribute name="firstAttribute" value="123"/>
                   <Attribute name="sampleone" value="554"/>
                   <Attribute name="area" value="newarea"/>
                   <Attribute name="group" value="samplegroup"/>
                   <Attribute name="whatever" value="uuu"/>
                </Attributes>
             </OperationData>
          </OperationInfo>
       </Body>
    </Envelope>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement where I have to convert timezone from UTC to a
I have some requirement that needed to convert the given inline css element to
We have a requirement where we need to convert from .wav file to .mp3
I am using JBoss Drools. I have a business requirement as defined below. and
I have requirement to import Excel file in MySQL database using Java. I Googled
I have a requirement to compress, convert and generate thumnails from video uploads. The
I'm using VS2010 and C#. I have one DataTable which I want to convert
Basically, I have this requirement to convert a present/future weekday to a timestamp. Example:
I am using a web2py application, in that I have a requirement like, In
I m using Dompdf to convert Html Page to PDF. As client's requirement pdf

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.