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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:32:21+00:00 2026-05-23T00:32:21+00:00

I have the xml file in the following format. <root> … <start/> some text

  • 0

I have the xml file in the following format.

<root>
...

<start/>
 some text <b> bold </b>
<end/>
...

<start/>
 some other text <i>italic </i>
<end/>
...
</root>

Please suggest me a xsl template that selects all the text that is between <start/> and <end/> tags. Please note <start/> and <end/> are empty nodes.
Thank you very 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-05-23T00:32:22+00:00Added an answer on May 23, 2026 at 12:32 am

    I’m interpreting your “all the text” to include not only text nodes themselves but also markup such as <b>. I’m also assuming that you do not want to select every descendant node between <start/> and <end/> but only the top-level ones. Further I’m assuming that all the <start/> and <end/> tags are siblings (cannot occur at just any level).

    Use the following template to select (and copy) all the text that is between <start/> and <end/> tags.

    <xsl:template match="/">
       <xsl:copy-of select="(//start)[1]/following-sibling::node()[not(self::end) and 
             name((preceding-sibling::start | preceding-sibling::end)[last()]) = 'start']"/>
    </xsl:template>
    

    Update:
    Given that your start/end can be at any level, you can remove the -sibling from the axes above:

      select="(//start)[1]/following::node()[not(self::end) and 
            name((preceding::start | preceding::end)[last()]) = 'start']"
    

    However, this selects all the nodes, not just the top-level ones. (And therefore if you deep-copy the selected nodes, you will get duplicates.) This is because it is not well-defined what behavior should happen if you had something like this:

    <start/>
    <chapter>foo<end/></chapter>
    

    Should <chapter> be selected or not?
    However if you can put further constraints on where start/end can fall in relation to each other, we can do better. E.g. is every <end/> a sibling of the preceding <start/>? If so, you could do

    <xsl:key name="text-by-last-milestone" match="* | text()"
          use="generate-id((preceding-sibling::start | preceding-sibling::end)[last()])" />
    <xsl:template match="/">
       <xsl:for-each select="//start">
          <xsl:copy-of select="key('text-by-last-milestone', generate-id())"/>
       </xsl:for-each>
    </xsl:template>
    

    If not, it would be helpful for you to show a more extended sample of your input.

    FYI, these tags are referred to as “milestone” markup, so you may be able to find more information about processing them by searching on that term. Depending on what the constraints on your input XML are, they are also discussed as “concurrent markup”.

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

Sidebar

Related Questions

I have an XML file which is in the following format: <root> <category> <doctype>
I have an XML file in the following format: <doc> <id name=X> <type name=A>
I have an XML File with the following format: <containers> <container> <item> item name
I have an xml file in the following format: <food> <desert> cake <desert> </food>
I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom'
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
All, I have a config xml file in the following format: <?xml version=1.0?> <configdata>
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a
I have xml file that defines some preference screens like the following example <PreferenceScreen
I have an XML file with the following format: <?xml version=1.0 encoding=UTF-8?> <Items> <Item

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.