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

Related Questions

This question would probably apply equally as well to other languages with C-like multi-line
I want to apply an XSLT Stylesheet to an XML Document using C# and
I need to apply some xml templates to various streams of xml data (and
What rules apply to the name that ends up in the exports section of
I have a base form with several controls including 1 label. This form is
I am trying to apply styles to HTML tags dynamically by reading in the
How do I apply the MarshalAsAttribute to the return type of the code below?
How do I apply 'use base' in Perl to inherit subs from some base
I'm trying to apply a transform to a 3D object in a STL File
when I apply the tag above my methods I get the error Type System.Runtime.CompilerServices.Extension

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.