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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:49:13+00:00 2026-05-25T09:49:13+00:00

I’m processing an XML document which has <paragraph> tags which contain text into a

  • 0

I’m processing an XML document which has <paragraph> tags which contain text into a plain-text file. Sometimes the lines are broken in odd places, and sometimes they are too long. I have a template for paragraphs that simply runs the apply-template action and appends a couple of newlines.

Is there a way to reformat the text() in the paragraph similar to the unix ‘fmt’ command (which rewraps the stream of text to a normalized width) after the apply-templates has a chance to handle other tags within the paragraph (such as bold, em, etc).

Also, is there a way for each reformatted line to be indented, as you would normally do in a block quote in a plain-text document?

  • 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-25T09:49:14+00:00Added an answer on May 25, 2026 at 9:49 am

    One easy solution is to use the str-split-to-lines template from FXSL like this:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:f="http://fxsl.sf.net/"
    xmlns:ext="http://exslt.org/common"
    xmlns:str-split2lines-func="f:str-split2lines-func"
    exclude-result-prefixes="xsl f ext str-split2lines-func"
    >
    
    
       <xsl:import href="dvc-str-foldl.xsl"/>
    
       <str-split2lines-func:str-split2lines-func/>
    
       <xsl:output indent="yes" omit-xml-declaration="yes"/>
    
        <xsl:template match="/">
          <xsl:call-template name="str-split-to-lines">
            <xsl:with-param name="pStr" select="/*"/>
            <xsl:with-param name="pLineLength" select="50"/>
            <xsl:with-param name="pDelimiters" select="' &#9;&#10;&#13;'"/>
          </xsl:call-template>
        </xsl:template>
    
        <xsl:template name="str-split-to-lines">
          <xsl:param name="pStr"/>
          <xsl:param name="pLineLength" select="60"/>
          <xsl:param name="pDelimiters" select="' &#9;&#10;&#13;'"/>
    
          <xsl:variable name="vsplit2linesFun"
                        select="document('')/*/str-split2lines-func:*[1]"/>
    
          <xsl:variable name="vrtfParams">
           <delimiters><xsl:value-of select="$pDelimiters"/></delimiters>
           <lineLength><xsl:copy-of select="$pLineLength"/></lineLength>
          </xsl:variable>
    
          <xsl:variable name="vResult">
              <xsl:call-template name="dvc-str-foldl">
                <xsl:with-param name="pFunc" select="$vsplit2linesFun"/>
                <xsl:with-param name="pStr" select="$pStr"/>
                <xsl:with-param name="pA0" select="ext:node-set($vrtfParams)"/>
              </xsl:call-template>
          </xsl:variable>
    
          <xsl:for-each select="ext:node-set($vResult)/line">
            <xsl:for-each select="word">
              <xsl:value-of select="concat(., ' ')"/>
            </xsl:for-each>
            <xsl:value-of select="'&#xA;'"/>
          </xsl:for-each>
        </xsl:template>
    
        <xsl:template match="str-split2lines-func:*" mode="f:FXSL">
          <xsl:param name="arg1" select="/.."/>
          <xsl:param name="arg2"/>
    
          <xsl:copy-of select="$arg1/*[position() &lt; 3]"/>
          <xsl:copy-of select="$arg1/line[position() != last()]"/>
    
          <xsl:choose>
            <xsl:when test="contains($arg1/*[1], $arg2)">
              <xsl:if test="string($arg1/word)">
                 <xsl:call-template name="fillLine">
                   <xsl:with-param name="pLine" select="$arg1/line[last()]"/>
                   <xsl:with-param name="pWord" select="$arg1/word"/>
                   <xsl:with-param name="pLineLength" select="$arg1/*[2]"/>
                 </xsl:call-template>
              </xsl:if>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="$arg1/line[last()]"/>
              <word><xsl:value-of select="concat($arg1/word, $arg2)"/></word>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>
    
          <!-- Test if the new word fits into the last line -->
        <xsl:template name="fillLine">
          <xsl:param name="pLine" select="/.."/>
          <xsl:param name="pWord" select="/.."/>
          <xsl:param name="pLineLength" />
    
          <xsl:variable name="vnWordsInLine" select="count($pLine/word)"/>
          <xsl:variable name="vLineLength" 
           select="string-length($pLine) + $vnWordsInLine"/>
          <xsl:choose>
            <xsl:when test="not($vLineLength + string-length($pWord) 
                               > 
                                $pLineLength)">
              <line>
                <xsl:copy-of select="$pLine/*"/>
                <xsl:copy-of select="$pWord"/>
              </line>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="$pLine"/>
              <line>
                <xsl:copy-of select="$pWord"/>
              </line>
              <word/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>
    
    </xsl:stylesheet>
    

    When this transformation is applied on an XML document like this one:

    <text>
    Dec. 13 — As always for a presidential inaugural, security and surveillance were
    extremely tight in Washington, DC, last January. But as George W. Bush prepared to
    take the oath of office, security planners installed an extra layer of protection: a
    prototype software system to detect a biological attack. The U.S. Department of
    Defense, together with regional health and emergency-planning agencies, distributed
    a special patient-query sheet to military clinics, civilian hospitals and even aid
    stations along the parade route and at the inaugural balls. Software quickly
    analyzed complaints of seven key symptoms — from rashes to sore throats — for
    patterns that might indicate the early stages of a bio-attack. There was a brief
    scare: the system noticed a surge in flulike symptoms at military clinics.
    Thankfully, tests confirmed it was just that — the flu.
    </text>
    

    The wanted output (words wrapped in lines with maximum width of 50) is produced:

    Dec. 13 — As always for a presidential inaugural, 
    security and surveillance were extremely tight in 
    Washington, DC, last January. But as George W. 
    Bush prepared to take the oath of office, security 
    planners installed an extra layer of protection: a 
    prototype software system to detect a biological 
    attack. The U.S. Department of Defense, together 
    with regional health and emergency-planning 
    agencies, distributed a special patient-query 
    sheet to military clinics, civilian hospitals and 
    even aid stations along the parade route and at 
    the inaugural balls. Software quickly analyzed 
    complaints of seven key symptoms — from rashes to 
    sore throats — for patterns that might indicate 
    the early stages of a bio-attack. There was a 
    brief scare: the system noticed a surge in flulike 
    symptoms at military clinics. Thankfully, tests 
    confirmed it was just that — the flu.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.