Solved

xsl template for converting string to xsl-fo table

Posted on 2010-08-13
1
492 Views
Last Modified: 2013-11-08
Dear experts,

here is the story:
-from the database I get a simple string, which i just need to output to a table cell,
-but sometimes I get a string which has newlines (	 )and tab character (
) in it,
--whenever I get this kind of string, I'd like to output it in a table cell which would mimic the NL&TAB formatting

I wanted to mimic the formatting by the means of a table. I am able to convert newlines to <fo:table-rows> and recursively print it out, but now I am stuck with recursivelly creating table-cells.

The code bellow creates table with corresponding number of rows (each new line is new table row)

Can anyone help me with creating a full table?
<xsl:template name="format_string">
		<xsl:param name="niz"/>
		<fo:table>
			<fo:table-body>
				<xsl:call-template name="format_string2tablerows">
					<xsl:with-param name="niz" select="$niz" />
				</xsl:call-template>
			</fo:table-body>
		</fo:table>
	</xsl:template>

	<xsl:template name="format_string2tablerows">
		<xsl:param name="niz" />
		<xsl:choose>
			<xsl:when test="contains($niz,'&#10;')">
				<fo:table-row>
					<fo:table-cell>
						<fo:block><xsl:value-of select="substring-before($niz,'&#10;')" /></fo:block>
					</fo:table-cell>
				</fo:table-row>
				<xsl:call-template name="format_string2tablerows">
					<xsl:with-param name="niz" select="substring-after($niz,'&#10;')" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<fo:table-row>
					<fo:table-cell>
						<fo:block>			
							<xsl:call-template name="format_object">
								<xsl:with-param name="niz" select="$niz" />
							</xsl:call-template>
						</fo:block>
					</fo:table-cell>
				</fo:table-row>
			</xsl:otherwise>
		</xsl:choose>				
	</xsl:template>

Open in new window

0
Comment
Question by:zeldi
1 Comment
 

Accepted Solution

by:
zeldi earned 0 total points
ID: 33435896
Never mind, I've found a solution by myself.

<xsl:template name="format_string">
		<xsl:param name="niz"/>
		<fo:table>
			<fo:table-body>
				<xsl:call-template name="format_string2tablerows">
					<xsl:with-param name="niz" select="$niz" />
				</xsl:call-template>
			</fo:table-body>
		</fo:table>
	</xsl:template>
	<xsl:template name="format_string2tablerows">
		<xsl:param name="niz" />
		<xsl:choose>
			<xsl:when test="contains($niz,'&#10;')">
				<fo:table-row>
					<xsl:call-template name="format_string2tablecells">
						<xsl:with-param name="niz" select="substring-before($niz,'&#10;')" />
					</xsl:call-template>
				</fo:table-row>
				<xsl:call-template name="format_string2tablerows">
					<xsl:with-param name="niz" select="substring-after($niz,'&#10;')" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<fo:table-row>
					<xsl:call-template name="format_string2tablecells">
						<xsl:with-param name="niz" select="$niz" />
					</xsl:call-template>
				</fo:table-row>
			</xsl:otherwise>
		</xsl:choose>				
	</xsl:template>
	<xsl:template name="format_string2tablecells">
		<xsl:param name="niz" />
		<xsl:choose>
			<xsl:when test="contains($niz,'&#9;')">
				<fo:table-cell>
					<fo:block>
						<xsl:call-template name="format_object">
							<xsl:with-param name="niz" select="substring-before($niz,'&#9;')" />
						</xsl:call-template>					
					</fo:block>
				</fo:table-cell>
				<xsl:call-template name="format_string2tablecells">
					<xsl:with-param name="niz" select="substring-after($niz,'&#9;')" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<fo:table-cell>
					<fo:block>			
						<xsl:call-template name="format_object">
							<xsl:with-param name="niz" select="$niz" />
						</xsl:call-template>
					</fo:block>
				</fo:table-cell>
			</xsl:otherwise>
		</xsl:choose>				
	</xsl:template>

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RSS Feed Enclosure URL 1 121
Create html table using xsl 8 36
AL3 Files 4 27
Eliminate additional border 1 17
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now