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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:54:11+00:00 2026-05-27T22:54:11+00:00

<merge> <text> <div begin=A end=B /> <div begin=C end=D /> <div begin=E end=F />

  • 0
<merge>
    <text>
        <div begin="A"   end="B" />
        <div begin="C"   end="D" />
        <div begin="E"   end="F" />
        <div begin="G"   end="H" />
    </text>
</merge>

I need a UNIONed set of attribute nodes, in the order A,B,C,D,E,F,G,H, and this will work:

/merge/text/div/@begin | /merge/text/div/@end

but only if each @begin comes before each @end, since the UNION operator is spec’d to return nodes in document order. (Yes?)

I need the nodeset to be in the same order, even if the attributes appear in a different order in the document, as here:

<merge>
    <text>
        <div end="B"   begin="A" />
        <div begin="C" end="D"   />
        <div end="F"   begin="E" />
        <div begin="G" end="H"   />
    </text>
</merge>

That is, I need elements to follow document order, but the attributes in each element to follow a determined order (either specified or alphabetical by attribute name).

  • 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-27T22:54:11+00:00Added an answer on May 27, 2026 at 10:54 pm

    This simply isn’t possible in pure XPath. First of all, attributes in XML are unordered. From the XML 1.0 Recommendation:

    Note that the order of attribute specifications in a start-tag or
    empty-element tag is not significant.

    An XPath engine might be reading and storing them in the order they appear in the document, but in terms of the spec, this is just a happy coincidence that cannot be relied upon.

    Second, XPath has no sorting functionality. So, your best option is to sort the elements in your host language (e.g. XSLT or a general-purpose PL) after they’ve been selected.

    Here’s how to sort those attributes by value in XSLT:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:template match="/">
            <xsl:apply-templates
                select="/merge/text/div/@*[name()='begin' or name()='end']">
                <xsl:sort select="."/>
            </xsl:apply-templates>
        </xsl:template>
    </xsl:stylesheet>
    

    Note that I also merged your two expressions into one.

    Edit: Use the following to output begin/end pairs in document order (as described in the comments):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:strip-space elements="*"/>
        <xsl:template match="div">
            <xsl:value-of select="concat(@begin, @end)"/>
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck with this : I need to merge two text files in a
This is in regards to merge XCode project.pbxproj files, but the same principle applies
I need to combine/merge two php functions, but I can't get the syntax right.
I'm using this code to merge text with an image and it's working fine.
I need to merge two XML documents, overwriting the overlapsed attributes and elements. For
I'm trying to merge two main menus together, but am having problems getting the
I need to merge a whole bunch of docx files programatically. Imagine they are
I have multiple text files that represent logging entries which I need to parse
When a text conflict occurs in Bazaar (and many other dvcs) a .BASE, .THIS
I need to seperate the checked and unchecked check box from set of check

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.