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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:10:17+00:00 2026-05-21T09:10:17+00:00

I have a xml that looks like this, <Parent> Running text with marked up

  • 0

I have a xml that looks like this,

<Parent> Running text with marked up entities like 
  <Child>Entity1</Child> 
 and, text in the middle too, and
  <Child> Entity2 </Child>
</Parent>

I have to preserve the line breaks and indentation when rendering the parent, but also apply a highlighting template to every child tag.

Now, the moment I capture the contents of the parent tag in a variable to do some string processing in XSL, I lose the underlying xml structure and cant apply the highlighting template to the children.

Whereas, I cant think of any other way to preserve the line breaks and indentation of the text contained in the parent tag.

Any ideas?

  • 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-05-21T09:10:18+00:00Added an answer on May 21, 2026 at 9:10 am

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:preserve-space elements="*"/>
        <xsl:template match="Parent">
            <div>
                <xsl:apply-templates mode="preserve"/>
            </div>
        </xsl:template>
        <xsl:template match="text()" mode="preserve" name="split">
            <xsl:param name="pString" select="."/>
            <xsl:choose>
                <xsl:when test="contains($pString,'&#xA;')">
                    <xsl:value-of select="substring-before($pString,'&#xA;')"/>
                    <br/>
                    <xsl:call-template name="split">
                        <xsl:with-param name="pString"
                         select="substring-after($pString,'&#xA;')"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$pString"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template match="Child" mode="preserve">
            <b>
                <xsl:apply-templates mode="preserve"/>
            </b>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <div> Running text with marked up entities like<br/> <b>Entity1</b><br/> and, text in the middle too, and<br/> <b> Entity2 </b><br/></div>

    Render as:

    Running text with marked up entities like
    Entity1
    and, text in the middle too, and
    Entity2

    Edit: Better example preserving whitespace only text nodes.

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

Sidebar

Related Questions

I have an xml that looks something like this <para> text text text <b>text</b>
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have an xml that looks like this: <Config> <A></A> <Template><B/><C/></Template> </Config> and I
I have a XML Structure that looks like this. <sales> <item name=Games sku=MIC28306200 iCat=28
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
Say I have a xml document that looks like this <foo> <bar id=9 />
I have an XML feed that looks like this: <?xml version=1.0 encoding=UTF-8?> <productFeed version=1.0
I have some XML that looks like this: <abc x={></abc> I want to force
I have an xml that looks like this <words> <word>word1</word> <word>word2</word> <word>word3</word> <word>word4</word> </words>
I have some xml that looks like this... <tbody> <tr> <td> <h5> <a class=foo

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.