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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:25:57+00:00 2026-05-26T07:25:57+00:00

I have an XML with a text node, and I need to split this

  • 0

I have an XML with a text node, and I need to split this string into multiple chunks using XSLT 2.0. For example:

<tag>
    <text>This is a long string 1This is a long string 2This is a long string 3This is a long string 4</text>
</tag>

The output should be:

<tag>
    <text>This is a long string 1</text>
    <text>This is a long string 2</text>
    <text>This is a long string 3</text>
    <text>This is a long string 4</text>
</tag>

Note that I deliberately set the chunk size to the length of each statement so that the example is easier to read and write, but the transformation should accept any value (it is okay for this value to be hardcoded).

  • 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-26T07:25:58+00:00Added an answer on May 26, 2026 at 7:25 am

    This XSLT 1.0 transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:param name="pChunkSize" select="23"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text/text()" name="chunk">
      <xsl:param name="pText" select="."/>
    
      <xsl:if test="string-length($pText) >0">
       <text><xsl:value-of select=
       "substring($pText, 1, $pChunkSize)"/>
       </text>
       <xsl:call-template name="chunk">
        <xsl:with-param name="pText"
        select="substring($pText, $pChunkSize+1)"/>
       </xsl:call-template>
      </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <tag>
        <text>This is a long string 1This is a long string 2This is a long string 3This is a long string 4</text>
    </tag>
    

    produces the wanted, correct result:

    <tag>
        <text>
            <text>This is a long string 1</text>
            <text>This is a long string 2</text>
            <text>This is a long string 3</text>
            <text>This is a long string 4</text>
            <text/>
        </text>
    </tag>
    

    II. XSLT 2.0 solution (non-recursive):

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:param name="pChunkSize" select="23"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text/text()">
      <xsl:variable name="vtheText" select="."/>
      <xsl:for-each select=
          "0 to string-length() idiv $pChunkSize">
       <text>
        <xsl:sequence select=
         "substring($vtheText, . *$pChunkSize +1, $pChunkSize) "/>
       </text>
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file which I'd like to parse into a non-XML (text)
If I have some xml like this: <mynode> <mysubnode> <mysubsubnode>hello world</mysubsubnode> some more text
for example, i have this xml <elements> <a> <b>6</b> <b>5</b> <b>6</b> </a> <a> <b>5</b>
I need to iterate through multiple-node structures, but this structure is only identified by
I'm trying to get a newline into a text node using XText from the
I have some XML thus <root> <TemplateNode> <Heading> <ID>1</ID> <Name>HeadingNodeTest</Name> <Order>1</Order> <Text>This is a
I have an xml that has text within word elements e.g <word>Police</word> <word>confirmed</word> <word>they
I have some xml files that contain text, which are displayed on my website.
I have seen XML Schema element with attributes containing only text but I have
I have the following text in xml file: <Config Builder=LP Wizard> <Libraries> <Library Name=XCAMSource/>

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.