#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    2
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Venezuela
    Posts
    95
    Rep Power
    16
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    42
    Rep Power
    15
    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>
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    2
    Rep Power
    0

    Great!


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

    Cheers,

IMN logo majestic logo threadwatch logo seochat tools logo