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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:00:37+00:00 2026-05-12T12:00:37+00:00

I would like to select a node and modify its attributes and child-nodes using

  • 0

I would like to select a node and modify its attributes and child-nodes using an
xsl:script function. In addition, templates matching child-nodes of that node should
STILL perform their job (after script is done processing the node).

  1. Can it be done using XSLT?
  2. Can you please provide an example / skeleton for such a transformation?
  • 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-12T12:00:37+00:00Added an answer on May 12, 2026 at 12:00 pm

    Yes, it can be done. I don’t seem to see what the problem is because the XML (or whatever output) of an XSL script is buffered independently from its input.

    This is illustrated in the following example whereby a simple XSL script copies an input XML document mostly as-is, changing a few things:

    • the root element name and attribute
    • flattening by removing the element from the hierarchy
    • dropping the results/date element
    • rename the item’s ‘source’ attribute ‘origin’
    • change the item’s ‘level’ attribute value
    • rename the FirstName and LastName elements of the item elements

    Sample input

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <MyRoot version="1.2">
        <results>
            <info>Alpha Bravo</info>
            <author>Employee No 321</author>
            <date/>
            <item source="www" level="6" cost="33">
                <FirstName>Jack</FirstName>
                <LastName>Frost</LastName>
                <Date>1998-10-30</Date>
                <Organization>Lemon growers association</Organization>
             </item>
             <item source="db-11" level="1" cost="65" qry="routine 21">
                <FirstName>Mike</FirstName>
                <LastName>Black</LastName>
                <Date>2006-10-30</Date>
                <Organization>Ford Motor Company</Organization>
             </item>
        </results>
    </MyRoot>
    

    Output produced

    <?xml version="1.0" encoding="utf-16"?>
    <MyNewRoot version="0.1">
        <author>Employee No 321</author>
        <info>Alpha Bravo</info>
        <item cost="33" origin="www" level="77">
            <GivenName>Jack</GivenName>
            <FamilyName>Frost</FamilyName>
            <Date>1998-10-30</Date>
            <Organization>Lemon growers association</Organization>
        </item>
        <item cost="65" qry="routine 21" origin="db-11" level="77">
            <GivenName>Mike</GivenName>
            <FamilyName>Black</FamilyName>
            <Date>2006-10-30</Date>
            <Organization>Ford Motor Company</Organization>
        </item>
    </MyNewRoot>
    

    XSL script

    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      exclude-result-prefixes="#default">
    
    <xsl:template match="MyRoot">
       <xsl:call-template name="MainTemplate">
       </xsl:call-template>
    </xsl:template>
    
    <xsl:template name="MainTemplate">
       <MyNewRoot version="0.1">
    
       <xsl:copy-of select="results/author" />
       <xsl:copy-of select="results/info" />
    
       <xsl:for-each select="results/item">
          <xsl:call-template name="FixItemElement"/>
       </xsl:for-each>
    
      </MyNewRoot> 
    </xsl:template>
    
    <xsl:template name="FixItemElement">
        <xsl:copy>
            <xsl:copy-of select="@*[not(name()='source' or name()='level')]" />
            <xsl:attribute name="origin">
                <xsl:value-of select="@source"/>
            </xsl:attribute>
            <xsl:attribute name="level">
                <xsl:value-of select="77"/>
            </xsl:attribute>
    
            <xsl:for-each select="descendant::*">
              <xsl:choose>
                <xsl:when test="local-name(.) = 'FirstName'">
                    <GivenName>
                       <xsl:value-of select="."/>
                    </GivenName>
                </xsl:when>
                <xsl:when test="local-name(.) = 'LastName'">
                     <FamilyName>
                       <xsl:value-of select="."/>
                    </FamilyName>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:copy>
                     <xsl:apply-templates select="@*|node()"/>
                  </xsl:copy>
                </xsl:otherwise>
              </xsl:choose>       
            </xsl:for-each>       
        </xsl:copy>
    </xsl:template> 
    

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

Sidebar

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.