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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:22:56+00:00 2026-05-22T03:22:56+00:00

I need to arrange the nodes in XHTML in particular predefined order using XSL,

  • 0

I need to arrange the nodes in XHTML in particular predefined order using XSL, retaining all the other transformation within the nodes. The input file is:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
  </head> 

  <body class="hresume">

    <div id="sec 1">
      <div>
    text 1
    <span class="summary">position 1</span>
      </div>
    </div>

    <div id="sec 2">
      <div>
    text 2
    <span class="summary">position 2</span>
      </div>
    </div>

  </body> 
</html> 

the XML transformation:

<?xml version="1.0"?>

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

<!-- the identity template -->
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<!-- remove summary -->
<xsl:template match="xhtml:span[@class='summary']"/>

<!-- arrange nodes -->
<do-something match="id('sec 2')"/>
<do-something match="id('sec 1')"/>

</xsl:stylesheet>

The expected result is just swapping “sec 1” and “sec 2” nodes and removing “summary” positions. What should be used instead of do-something?

  • 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-22T03:22:57+00:00Added an answer on May 22, 2026 at 3:22 am

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="http://www.w3.org/1999/xhtml"
     >
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
      "*[x:div[@id='sec 1'] and x:div[@id='sec 2']]">
      <xsl:copy>
       <xsl:apply-templates select="@*"/>
    
       <xsl:variable name="vDivs" select="x:div"/>
    
       <xsl:apply-templates select="$vDivs[2]"/>
       <xsl:apply-templates select="$vDivs[1]"/>
      </xsl:copy>
     </xsl:template>
     <xsl:template match="x:span[@class='summary']"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        </head>
        <body class="hresume">
            <div id="sec 1">
                <div>     text 1     
                    <span class="summary">position 1</span>
                </div>
            </div>
            <div id="sec 2">
                <div>     text 2     
                    <span class="summary">position 2</span>
                </div>
            </div>
        </body>
    </html>
    

    produces exactly the wanted, correct result:

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
       </head>
       <body class="hresume">
          <div id="sec 2">
             <div>     text 2     
            </div>
          </div>
          <div id="sec 1">
             <div>     text 1     
            </div>
          </div>
       </body>
    </html>
    

    Do note:

    1. The wanted special effect is achieved by having two separate <xsl:apply-templates> instructions specified in the desired order.

    2. The wanted switching of places between the two div elements is achieved even if the second one were preceding the first one — in the result always the one that was second (of the two) in document order is now first (of the two) in document order.

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

Sidebar

Related Questions

I need to arrange the nodes in a particular way. I have tried with
I want to use the DataAnnotations.DisplayAttribute.Order property to arrange my fields when using the
What I need is to re-arrange the columns in a table by the order
I create reminders and I need to sort or arrange the order in ascending
I need to take rows from two separate tables, and arrange them in descending
need a quick help here. I have a series of hyperlinks all with the
I need to re - arrange a large XML document (size > 50 GB)
I need to start building a image application and my customer wants to arrange
I have a JTree in which the user can drag/drop or re-arrange nodes, upon
I need to arrange multiple div's like, code: <style> #div1 { background: yellow; float:left;

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.