|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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> |
|
#4
|
|||
|
|||
|
Great!
Thanks immensely 'teedee' for your help. It really worked great!
Cheers, |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Parsing and formating a string through XSL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|