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

  • Home
  • SEARCH
  • 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 182729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:59:28+00:00 2026-05-11T14:59:28+00:00

How do I apply a change to text in an element without losing its

  • 0

How do I apply a change to text in an element without losing its child elements.

For example:

I have this xml that I would like to apply a change to the text inside the ‘p’ element….

<section>     <p >Awesome LO</p>     <p >         Begin with an interesting fact, thought-provoking         <keyword>question</keyword>         <context>             <p type='Key Words Head'>Banana</p>             <p type='Key Words'>A tasty treat to eat any time, and good with ice cream – a banana split.</p>         </context>, or a one sentence scenario to illustrate why the learning object (content) is important.     </p>     <p >         Begin with a definition, if required. Then, provide an example by example view.     </p> </section> 

So my xsl looks like this….

<xsl:template match='p'>     <xsl:copy>         <xsl:call-template name='widont-title'>             <xsl:with-param name='text' select='text()' />         </xsl:call-template>     </xsl:copy> </xsl:template> 

The problem is that I lose the ‘keyword’, ‘context’, and other elements inside of the ‘p’ when I do this. Can anyone point me to any clues? Thanks!

<!-- this method puts a non breaking space in the last word of a 'p' if its less than 5 characters--> <xsl:template name='widont-title'>     <xsl:param name='temp'/>     <xsl:param name='text'/>     <xsl:param name='minWidowLength' select='5'/>      <xsl:choose>         <xsl:when test='contains($text, ' ')'>             <xsl:variable name='prev' select='substring-before($text,' ')'/>             <xsl:variable name='before' select='concat($temp,' ',$prev)'/>             <xsl:variable name='after' select='substring-after($text, ' ')'/>              <xsl:choose>                 <xsl:when test='contains($after, ' ')'>                     <xsl:call-template name='widont-title'>                         <xsl:with-param name='temp' select='$before'/>                         <xsl:with-param name='text' select='$after'/>                     </xsl:call-template>                 </xsl:when>                 <xsl:when test='not(contains($after, ' ')) and string-length(translate($after,'`~!@#$%^\*()-_=+\\|]}[{;:,./?&lt;&gt;','')) &lt; $minWidowLength'>                      <xsl:value-of select='concat($before, '&#160;', $after)' />                 </xsl:when>                 <xsl:otherwise>                     <xsl:value-of select='concat($before, ' ', $after)' />                 </xsl:otherwise>             </xsl:choose>         </xsl:when>         <xsl:otherwise>             <xsl:value-of select='$text'/>         </xsl:otherwise>     </xsl:choose> </xsl:template> 
  • 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. 2026-05-11T14:59:28+00:00Added an answer on May 11, 2026 at 2:59 pm

    It is not clear what the widont-title template does and whether this is correctly implemented (looks a little-bit too-complicated), but the problem is that this template is applied too-soon, not leaving any possibilities for children elements of p to be processed.

    The solution (using the identity template and overriding it for p/text() nodes) is very simple:

    <xsl:stylesheet version='1.0'  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>     <xsl:output omit-xml-declaration='yes'/>     <xsl:template match='node()|@*'>         <xsl:copy>             <xsl:apply-templates select='node()|@*'/>         </xsl:copy>     </xsl:template>     <xsl:template match='p/text()'>         <xsl:call-template name='widont-title'>             <xsl:with-param name='text' select='.' />         </xsl:call-template>     </xsl:template>           <!-- 'widont-title' template omitted for brevity -->  </xsl:stylesheet> 

    when the above transformation is applied on the provided XML document, the children of any p element are correctly present in the output.

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

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer According to this, the tab was removed from newer versions… May 11, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer Looks like an issue with the jQuery plugin to me.… May 11, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer There isn't anything you can put in the model definition… May 11, 2026 at 6:05 pm

Related Questions

have downloaded Orca to edit an MSI file. I want to remove some banner
Has anyone come up with a good way of performing full text searches (
I've implemented the YUI Editor and would like to apply a CSS to change
I'm new to JQuery, so this is probably a very dumb question. I've used

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.