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 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

Related Questions

I'm not interested in call or apply to change the this reference. Just for
I need to merge certain xml nodes based on an attribute value, change that
I have a StackPanel that I dynamically change the contents of every 5 minutes
I'd like to change the text on a property sheet APPLY button but I
this is a text field, new_id is an integer. When I apply the following
This is my XML: <?xml version=1.0 encoding=UTF-8?> <?xml-stylesheet href=test_2.xsl type=text/xsl?> <doc xmlns=http://www.foo.org> <div> <title>Mr.
I need to create a simple rich-text editor that saves its contents to an
I have a bunch of LI elements for which I need to change the
I have a simple form like this: <form id='myForm'> <input type='text' name='Textbox'> <select name='SelectBox'>
When I apply WebKit transform change to the dom style attr, for instance: Change

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.