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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:25:40+00:00 2026-05-23T22:25:40+00:00

Trying to create a PDF file based on an XML and a file using

  • 0

Trying to create a PDF file based on an XML and a file using XMLSpy.

I’m trying to split a field into two lines based on the field content.

For example, if my varialbe = “John Doe AKA Johnny D”, I want to view it like this :

John Doe

Johnny D

My problem is that I can’t make it work even with all the samples on the net.

Here’s my code :

     <xsl:value-of disable-output-escaping="yes" select="concat(substring-before(//MyField,'AKA'),$newline,substring-after(//MyField,'AKA'))" /> 
  </xsl:when>

So basically, eveytime I find the “AKA” string, I want to break the field into two lines.
So my code, finds the string, create the new variable but still shows in one line.
I’ve tried creating a variable with a blank line, using all kinds of techiniques but still shows in one line.

Any thoughts ?

  • 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-23T22:25:41+00:00Added an answer on May 23, 2026 at 10:25 pm

    See my answer here about using a hex entity reference and linefeed-treatment.


    Edit

    I took your code from the comments and put it in template in a sample XSLT stylesheet. The only thing I changed was:

    1. I changed your newline variable to &#xA;.
    2. I added linefeed-treatment="preserve" to your fo:block.

    Using a dummy XML file and the XSLT stylesheet, I produced an XSL-FO document that when rendered with FOP, produces “John Doe” and “Johnny D” on separate lines.

    Here is the XML file:

    <doc>
      <MyField>John Doe AKA Johnny D</MyField>
    </doc>
    

    Here is the XSLT stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:output indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="/">
        <fo:root>
          <fo:layout-master-set>
            <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
              <fo:region-body margin="1in" margin-top="1.5in"/>
            </fo:simple-page-master>
          </fo:layout-master-set>
          <fo:page-sequence master-reference="my-page">
            <fo:flow flow-name="xsl-region-body">
              <xsl:apply-templates/>
            </fo:flow>
          </fo:page-sequence>
        </fo:root>
      </xsl:template>
    
      <xsl:template match="doc">
        <xsl:variable name="newline" select="'&#xA;'"/>        
        <xsl:variable name="MyVar">
          <xsl:choose>
            <xsl:when test="contains(//MyField,'AKA')">
              <xsl:value-of select="concat(substring-before(//MyField,'AKA'),$newline,substring-after(//MyField,'AKA'))"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="//MyField"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <fo:block linefeed-treatment="preserve">
          <xsl:value-of select="$MyVar"/>
        </fo:block>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Here is the resulting XSL-FO:

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
       <fo:layout-master-set>
          <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
             <fo:region-body margin="1in" margin-top="1.5in"/>
          </fo:simple-page-master>
       </fo:layout-master-set>
       <fo:page-sequence master-reference="my-page">
          <fo:flow flow-name="xsl-region-body">
             <fo:root>
                <fo:layout-master-set>
                   <fo:simple-page-master page-height="11in" page-width="8.5in" master-name="my-page">
                      <fo:region-body margin-top="1.5in" margin="1in"/>
                   </fo:simple-page-master>
                </fo:layout-master-set>
                <fo:page-sequence master-reference="my-page">
                   <fo:flow flow-name="xsl-region-body">
                      <fo:block linefeed-treatment="preserve">John Doe 
     Johnny D</fo:block>
                   </fo:flow>
                </fo:page-sequence>
             </fo:root>
          </fo:flow>
       </fo:page-sequence>
    </fo:root>
    

    The PDF is a single 8.5″ x 11″ page with this on it:

    John Doe
    Johnny D
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a sitemap using Linq to Xml, but am getting an
I'm trying to generate a PDF file using AJAX call in Rails3. The following
I'm trying to write metadata to a pdf file using the following python code:
I'm trying to create a self-contained version of pisa (html to pdf converter, latest
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
hi i am trying to create a pdf files in php useing dompdf-0.5.1 i
I'm trying to create an application that converts a file from the HTML format
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create a user account in a test. But getting a Object reference

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.