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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:07:58+00:00 2026-06-04T16:07:58+00:00

I want to write a template to process some section and reuse it. In

  • 0

I want to write a template to process some section and reuse it.

In the below XML, we see Message is repeated in every ,,. I want to write a template to process and call it when ever needed.

        <Data>

           <A>
              <text>this is text</text>
              <Message>
                <local>Local  link</local>
                <STD>External link</STD>
                </Message>
            </A>
            <B>
               <info>Information</info>
               <Message>
                <local>Local uri link</local>
                <STD>External link uri</STD>

                </Message>
            </B>
            <C>
               <longtext>Long Text</longtext>
               <Message>
                <local>Local uri link</local>
                <STD>External link uri</STD>

                </Message>
                </C>
        <Data>

Output needed:

    <Information>     
          <AA>
                this is text
                <MSG local value="Local uri link" STD value="External link"/>
            </AA>

            <BB>
                Information
                <MSG local value  ="Local uri link"  STD value="External link"/>

            </BB>
            <CC>
                Long Text
                <MSG local value="Local uri link" STD value="External link"/>
            </CC>

    <Information>

While processing tag in every node, I am writing code for every tags in A, B, C.

Sample code written

    <Information>

        <xsl:template match="A">
        <AA>
            <xsl:value-of select="text"/>
            <xsl:element name="MSG">
                <xsl:attribute name="local value">
                    <xsl:value-of select="Message/local"/>
                </xsl:attribute>
                <xsl:attribute name="STD value">
                    <xsl:value-of select="Message/STD"/>
                </xsl:attribute>
        </AA>
    </Information>

similarly for every template I am explicitly writing the code for the block MSG.

Now I want to write a separate template to process . And I want to call this template from every template.

Basically I want to reuse the code written to process

Can any one help me how to do it.

Thank you.

  • 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-04T16:07:59+00:00Added an answer on June 4, 2026 at 4:07 pm

    Here is a sample:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="@* | node()">
      <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="Data">
      <Information>
        <xsl:apply-templates/>
      </Information>
    </xsl:template>
    
    <xsl:template match="Data/*">
      <xsl:element name="{local-name()}{local-name()}">
        <xsl:apply-templates/>
      </xsl:element>
    </xsl:template>
    
    <xsl:template match="Data/A/text | Data/B/info | Data/C/longtext">
      <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="Message">
      <MSG local-value="{local}" STD-value="{STD}"/>
    </xsl:template>
    
    </xsl:stylesheet>
    

    When applied to the input

    <Data>
    
       <A>
          <text>this is text</text>
          <Message>
            <local>Local  link</local>
            <STD>External link</STD>
            </Message>
        </A>
        <B>
           <info>Information</info>
           <Message>
            <local>Local uri link</local>
            <STD>External link uri</STD>
    
            </Message>
        </B>
        <C>
           <longtext>Long Text</longtext>
           <Message>
            <local>Local uri link</local>
            <STD>External link uri</STD>
    
            </Message>
            </C>
    </Data>
    

    Saxon 6.5.5 outputs

    <?xml version="1.0" encoding="utf-8"?><Information>
    
               <AA>
                  this is text
                  <MSG local-value="Local  link" STD-value="External link"/>
                </AA>
                <BB>
                   Information
                   <MSG local-value="Local uri link" STD-value="External link uri"/>
                </BB>
                <CC>
                   Long Text
                   <MSG local-value="Local uri link" STD-value="External link uri"/>
                    </CC>
            </Information>
    

    Neither your posted input sample nor the wanted output sample are well-formed XML so I had to make some changes to element or attribute names to process as well as to output XML.

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

Sidebar

Related Questions

I want to write a template function that checks some Timestamp property (class inherits
Question is in subject. I want to write some universal template function for safe
I want to write a MyGeneration Template File in F#. I know you can
I want to write a sign function template. I did it like this: template<class
I want to write a C++ template like this: template <class Type1, class Type2,
I want to write a python script that calls some external REST service and
I'm just a newer to JavaScript. I want to write a JS template class
The problem is - I want to write a template class in C++, put
In text i want to find structures like every thing till some text, but
I want to write a function that creates a Vector (template), stores a couple

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.