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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:51:11+00:00 2026-06-11T13:51:11+00:00

I am attempting to move a node into it’s previous sibling’s child, and the

  • 0

I am attempting to move a node into it’s previous sibling’s child, and the fact that everything is on the same level is making it a little tricky for me.

Illustration of my input:

<dl>
   <dlentry>
      <dt> Title 1 </dt>
      <dd> Title 1's definition </dd>
      <dt> Title 2 </dt>
      <dd> Title 2's definition </dd> 
      <dt> Title 3 </dt>
      <dd> Title 3's definition </dd>
   </dlentry>
</dl> 
<p> part of title 3's definition </p>
<p> another part of title 3's definition </p>

What I am attempting to do is to take those 2 <p> elements at the bottom and concatenate their text to end of the last <dd> element’s text in <dlentry> because they are a part of that definition for “Title 3”.

Desired output:

<dl>
   <dlentry>
      <dt> Title 1 </dt>
      <dd> Title 1's definition </dd>
      <dt> Title 2 </dt>
      <dd> Title 2's definition </dd> 
      <dt> Title 3 </dt>
      <dd> Title 3's definition part of title 3's definition another part of title 3's  definition </dd>
   </dlentry>
</dl>

Another issue I’m dealing with is because of how bad the XHTML is in my source document, I need to do a regex match to on the text for those <p> elements to make sure it doesn’t hit anywhere else in the document.

I was able to successfully insert the first <p>‘s text as desired but am having trouble getting it to work in so I can do my regex match and also getting that 2nd

element’s text into the desired location as well.

Here is a code fragment from my stylesheet, using XSLT 2.0.

<xsl:analyze-string select="."
      regex="my regex expression here">

<xsl:template match="dlentry">

  <xsl:matching-substring>
    <dlentry>
     ** <xsl:copy-of select="node()[ position() lt last()]"/>
         <dd>
           <xsl:copy-of select="node()[last()]/text()" />
           <xsl:copy-of select=" parent::node()/following-sibling::node()[1]/text()"/>
         </dd>
    </dlentry>
  </xsl:matching-substring>

  <xsl:non-matching-substring>
      <xsl:value-of select=".">
  </xsl:non-matching-substring>

</xsl:template>

<xsl:template match="p[preceding-sibling::node()[1][self::node()[name(.)='dl']]]" />
<xsl:template match="p[preceding-sibling::node()[2][self::node()[name(.)='dl']]]" />

At the code line with the ** asterisks Saxon throws an error saying “Axis step child::node() cannont be used here: the context item is an atomic value.” I am not familiar with analyze-string but if I run my copy-of selects outside of analyze-string and just in a template, it runs fine.

Sorry that this question was kind of long but I wanted to share everything I had to this point.

Thanks in advance.

  • 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-11T13:51:12+00:00Added an answer on June 11, 2026 at 1:51 pm

    This short and simple XSLT 1.0 (and of course it is also XSLT 2.0):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kFollowing" match="p" use="generate-id(preceding-sibling::dl[1])"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="dlentry/dd[last()]">
      <dd>
       <xsl:apply-templates select=
        "(.|key('kFollowing', generate-id(ancestor::dl[1])))/text()"/>
      </dd>
     </xsl:template>
     <xsl:template match="p"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <html>
        <dl>
            <dlentry>
                <dt> Title 1 </dt>
                <dd> Title 1's definition </dd>
                <dt> Title 2 </dt>
                <dd> Title 2's definition </dd>
                <dt> Title 3 </dt>
                <dd> Title 3's definition </dd>
            </dlentry>
        </dl>
        <p> part of title 3's definition </p>
        <p> another part of title 3's definition </p>
    </html>
    

    produces the wanted, correct result:

    <html>
       <dl>
          <dlentry>
             <dt> Title 1 </dt>
             <dd> Title 1's definition </dd>
             <dt> Title 2 </dt>
             <dd> Title 2's definition </dd>
             <dt> Title 3 </dt>
             <dd> Title 3's definition  part of title 3's definition  another part of title 3's definition </dd>
          </dlentry>
       </dl>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently attempting to move a JFrame (the same way you would by
I am attempting to bulk move my files to new folders that have new
Attempting to move an uploaded file so that it is saved in the directory,
I am attempting to create a code that will move an actor to a
Attempting to move a folder to the same parent ID returns 400 (Bad Request):
I am attempting to move to XE2 from Delphi 6. When I compile and
I am attempting to use the code found in the answer here: Directory.Move doesn't
Attempting to make a NSObject called 'Person' that will hold the login details for
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
I am attempting to move all controls on a form down or up by

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.