XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2004, 01:47 PM
relativity relativity is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 relativity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Parsing and formating a string through XSL

I am kind of new in XML and XSL, and I was wondering if anyone of you could assist me on the following question ....

I am generating a pdf file from xml and formating the output with xsl, however, there is a field which seems to be a long string coming out of xml that overlaps another field. This field consists on numbers seperated by commas, (for instance: 10,12,12,25,36,14,9,17,34,23).
What I am trying to accomplish is to split this long string coming out of xml into 2 lines, which of course will avoid overlapping the other field. Is there any way possible that I could apply through xsl in order to have this string splited into 2 lines? something like...
10,12,12,25,36,
14,9,17,34,23

Your help is greatly appreciated!

Thank you

Reply With Quote
  #2  
Old January 7th, 2004, 08:42 AM
dadelcas dadelcas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Venezuela
Posts: 95 dadelcas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 28 sec
Reputation Power: 6
Hey man, it is not an answer to your question. I'm Java Developer and I getting started on php enterprise development. I'm looking for information about pdf generation using xml, I notice that you are working with. Maybe you could let me some links or any help with that
__________________
-DdC

Reply With Quote
  #3  
Old January 7th, 2004, 06:08 PM
teedee teedee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 42 teedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Much harder than it sounds ... but possible by using substring-before and substring-after

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<xsl:call-template name="SplitCSV">
			<xsl:with-param name="CSVData">10,12,12,25,36,14,9,17,34,23</xsl:with-param>
			<!-- This emulates a ZERO based array -->
			<xsl:with-param name="SplitAtElementNumber">6</xsl:with-param>
			<xsl:with-param name="SeparatorCharacter">,</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="SplitCSV">
		<xsl:param name="NumberOfElementsFound">0</xsl:param>
		<xsl:param name="CSVData"/>
		<xsl:param name="SplitAtElementNumber"/>
		<xsl:param name="SeparatorCharacter"/>
		<xsl:variable name="ArrayElement" select="substring-before($CSVData, $SeparatorCharacter)"/>
		<xsl:variable name="RemainingString" select="substring-after($CSVData, $SeparatorCharacter)"/>
		<xsl:value-of select="$ArrayElement"/>
		<xsl:choose>
			<xsl:when test="contains($RemainingString, $SeparatorCharacter)">
				<xsl:value-of select="$SeparatorCharacter"/>
				<xsl:if test="$NumberOfElementsFound=$SplitAtElementNumber">
					<br/>
				</xsl:if>
				<xsl:call-template name="SplitCSV">
					<xsl:with-param name="NumberOfElementsFound" select="$NumberOfElementsFound +1"/>
					<xsl:with-param name="CSVData" select="$RemainingString"/>
					<xsl:with-param name="SplitAtElementNumber" select="$SplitAtElementNumber"/>
					<xsl:with-param name="SeparatorCharacter" select="$SeparatorCharacter"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$SeparatorCharacter"/>
				<xsl:value-of select="$RemainingString"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #4  
Old January 8th, 2004, 06:35 AM
relativity relativity is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 relativity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Great!

Thanks immensely 'teedee' for your help. It really worked great!

Cheers,

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Parsing and formating a string through XSL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT