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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:13:48+00:00 2026-06-10T18:13:48+00:00

I’m a bit stuck on how to proceed best with following XML example :

  • 0

I’m a bit stuck on how to proceed best with following XML example : What I have is the following :

<Story>
<Content para="div"><local>This is some (normal) text to start with.</local></Content>
<Content para="div"><local>Connect something (</local></Content>
<Content para="div"><local><refnr value="58236"/></local></Content>
<Content para="div"><local>) to something else (</local></Content>
<Content para="div"><local><refnr value="58237"/></local></Content>
<Content para="div"><local>), and make sure it's connected to this (</local></Content>
<Content para="div"><local><refnr value="58239"/></local></Content>
<Content para="div"><local>).</local></Content>
<Content para="div"><local>If that's ok do the same with this (</local></Content>
<Content para="div"><local><refnr value="58238"/></local></Content>
<Content para="div"><local>) also.</local></Content>
<Content para="div"><local>This is some normal text.</local></Content>
<Content para="div"><local>This also.</local></Content>
</Story>

and the output I’d like to get is as follows :

<Story>
<Content para="div"><local>This is some (normal) text to start with.</local></Content>
<Content para="div"><local>Connect something (<refnr value="58236"/>) to something else (<refnr value="58237"/>), and make sure it's connected to this (<refnr value="58239"/>).</local></Content>
<Content para="div"><local>If that's ok do the same with this (<refnr value="58238"/>) also.</local></Content>
<Content para="div"><local>This is some normal text.</local></Content>
<Content para="div"><local>This also.</local></Content>
</Story>

Or, to ‘code’ it : Any [Content para=div][local] node ending with an open bracket, needs to be merged with the following [Content para=div][local] nodes untill the node containing the last closing bracket and the end of the sentence (identified by closing dot). I was able to do some things, but it became overly complex and slow and without all wanted results. Any advice using xslt2 ?

  • 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-10T18:13:50+00:00Added an answer on June 10, 2026 at 6:13 pm

    This XSLT 2.0 transformation (can easily be translated to XSLT 1.0):

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/*">
      <Story>
       <xsl:apply-templates select="Content[1]/local"/>
      </Story>
     </xsl:template>
    
     <xsl:template match="Content/local[not(ends-with(., '('))]">
      <Content para="div"><local><xsl:apply-templates/></local></Content>
      <xsl:apply-templates select="../following-sibling::Content[1]"/>
     </xsl:template>
    
     <xsl:template match="Content/local[ends-with(., '(')]">
      <Content para="div"><local><xsl:apply-templates/>
       <xsl:apply-templates mode="inGroup" select="../following-sibling::Content[1]"/>
      </local></Content>
    
      <xsl:apply-templates select=
       "../following-sibling::Content
                 [local[starts-with(.,')') and ends-with(.,'.')]][1]
                   /following-sibling::Content[1]"/>
     </xsl:template>
    
     <xsl:template match="Content/local" mode="inGroup">
        <xsl:apply-templates/>
        <xsl:apply-templates mode="#current"
             select="../following-sibling::Content[1]"/>
     </xsl:template>
    
     <xsl:template mode="inGroup" match="Content/local[starts-with(.,')') and ends-with(.,'.')]">
      <xsl:apply-templates/>
     </xsl:template>
    
     <xsl:template match="refnr"><xsl:copy-of select="."/></xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <Story>
     <Content para="div"><local>This is some (normal) text to start with.</local></Content>
     <Content para="div"><local>Connect something (</local></Content>
     <Content para="div"><local><refnr value="58236"/></local></Content>
     <Content para="div"><local>) to something else (</local></Content>
     <Content para="div"><local><refnr value="58237"/></local></Content>
     <Content para="div"><local>), and make sure it's connected to this (</local></Content>
     <Content para="div"><local><refnr value="58239"/></local></Content>
     <Content para="div"><local>).</local></Content>
     <Content para="div"><local>If that's ok do the same with this (</local></Content>
     <Content para="div"><local><refnr value="58238"/></local></Content>
     <Content para="div"><local>) also.</local></Content>
     <Content para="div"><local>This is some normal text.</local></Content>
     <Content para="div"><local>This also.</local></Content>
    </Story>
    

    produces the wanted, correct result:

    <Story>
       <Content para="div">
          <local>This is some (normal) text to start with.</local>
       </Content>
       <Content para="div">
          <local>Connect something (<refnr value="58236"/>) to something else (<refnr value="58237"/>), and make sure it's connected to this (<refnr value="58239"/>).</local>
       </Content>
       <Content para="div">
          <local>If that's ok do the same with this (<refnr value="58238"/>) also.</local>
       </Content>
       <Content para="div">
          <local>This is some normal text.</local>
       </Content>
       <Content para="div">
          <local>This also.</local>
       </Content>
    </Story
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.