Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 13th, 2013, 07:31 AM
Authorized User
 
Join Date: Jun 2013
Posts: 21
Thanks: 2
Thanked 0 Times in 0 Posts
Default Dynamic line wrapping based on conditions-Need expert help

My output type is "text".I am preparing for Reports .My text output got to accept only 50 character width after that which has to be wrapped in to the next line.I have a solution to line wrap for the elements in the text.Is there any way to to wrap for the entire reports.?Instead of doing for the every line ,Can I do it for the whole document?

I have solutions for line wrap.My problem is ,I have many conditions like

Firstname lastname route (condition1 ) (condition2) (condition3) (condition4)..go on...
Let us assume
First name fixedwidth is 15, lastname fixed width is 15,city fixed width is 3...after that condition1 will have 10 width ,condition2 have 15 fixed with then go on....importantly these conditions are option only...

So 15+emptyspace+15+emptyspace+3 =36 My condition will start from 36 th column..

after the first wrap,I got to continue from the same line for the upcoming conditions.So for the next item i got find the start and end locations.
How to solve this problem.? I think It will be difficult one. I am expecting from expert help.
xml input:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<passengerlist>
<passengers>
<Firstname>JOHNNNNNNNNNNNN</Firstname>
<lastname>MARKKKKKKKKKKKK</lastname>
<comments>abcdefh abc abcde abc dekf jl</comments>
<route>air</route>
</passengers>
<!-- <passengers>
<Firstname>ANTONYYYYYYYYYYY</Firstname>
<lastname>NORMAN</lastname>
<comments>abcdefddddddddghhhhhhhhhhhhhh</comments>
<route>air</route>
</passengers>
<passengers>
<Firstname>BRITTOOOOOOOOOO</Firstname>
<lastname>MARKKKKKKK</lastname>
<comments>abcdedfffghghghghghghghghghghghghgh</comments>
<route>cruise</route>
</passengers> -->
</passengerlist>
XSLT Code
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
<xsl:variable name="newline"/> 

<!-- For line Wrapping -->
    
       <xsl:template name="callEmpty">
     		 	<xsl:param name="callEmpty"/>
      			<xsl:variable name="LNemptyCheck" select="$callEmpty"></xsl:variable>
    	</xsl:template> 
    
		<xsl:template name="text_wrapper">
			<xsl:param name="Text"/>
				<xsl:choose>
					<xsl:when test="string-length($Text)">
						<xsl:value-of select="substring($Text,1,15)"/>
							<xsl:if test="string-length($Text) &gt; 15">
								<xsl:value-of select="$newline"/>
							</xsl:if>
		<xsl:call-template name="wrapper_helper">
			<xsl:with-param name="Text" select="substring($Text,16)"/>   
		</xsl:call-template>
					</xsl:when>
				</xsl:choose>
		</xsl:template>

		<xsl:template name="wrapper_helper">
			<xsl:param name="Text"/>
				<xsl:value-of select="substring($Text,1,15)"/><xsl:text>&#xa;</xsl:text>
					<xsl:call-template name="text_wrapper">
						<xsl:with-param name="Text" select="substring($Text,15)"/>
					</xsl:call-template>
		</xsl:template> 
  <!-- Template for Line wrapping --> 
 
    <xsl:template match="/">
        
     <xsl:for-each select="passengerlist/passengers">
           
        <xsl:value-of select="Firstname"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="lastname"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="route"/>
        <xsl:text> </xsl:text>
<xsl:variable name="firstwrap">
	<xsl:if test="route='air'">
   
 		<xsl:value-of select="Firstname"/>
 		<xsl:text> </xsl:text>
 		<xsl:value-of select="comments"/>
 	</xsl:if>
</xsl:variable>
<xsl:call-template name="text_wrapper">
      <xsl:with-param name="Text" select="$firstwrap"/>
  </xsl:call-template>

 	
 	<xsl:variable name="secondwrap">
 	<xsl:if test="Firstname='JOHNNNNNNNNNNNN'">
 		<xsl:value-of select="lastname"/>
 		<xsl:text> </xsl:text>
 		<xsl:value-of select="comments"/>
 	</xsl:if>
 		</xsl:variable>
 		<xsl:call-template name="text_wrapper">
      <xsl:with-param name="Text" select="$secondwrap"/>
  </xsl:call-template> </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>
Output:
JOHNNNNNNNNNNNN MARKKKKKKKKKKKK air JOHNNNNNNNNNNNN abcdefh abc ab
bcde abc dekf jl
MARKKKKKKKKKKKK abcdefh abc ab
bcde abc dekf jl

Expected out:
JOHNNNNNNNNNNNN MARKKKKKKKKKKKK air JOHNNNNNNNNNNNN abcdefh abc ab
bcde abc dekf jl MARKKKKKKKKKKKK abcdefh abc abbcde abc dekf jl

Please help me to sort out my problem or tell me Is it possible in XSLT?
 
Old July 30th, 2013, 02:34 PM
Authorized User
 
Join Date: Jun 2013
Posts: 21
Thanks: 2
Thanked 0 Times in 0 Posts
Default I resolved it by assigning variable then wrapped

I resolved it by assigning variable then wrapped





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic line wrapping based on conditions-Need expert help sen1953 XSLT 0 July 13th, 2013 07:28 AM
for-each conditions based on row selections santhakumar XSLT 0 July 12th, 2013 07:59 AM
skip creating tag based on conditions sudheer.raju XSLT 3 December 20th, 2011 06:56 AM
Display or hide ModalPopupExtender based on client-site conditions Dmitriy ASP.NET 3.5 Professionals 5 August 20th, 2009 01:04 PM
selection based on conditions rajesh_css XSLT 3 October 2nd, 2008 08:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.