XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 17 Jan 2007 04:44 PM
I'm passing a very long string that I would like to format. For example...

<Address>
<xsl:value-of select="address"/>
</Address

Where address looks like this...123 Here Street There AA 11111

What I want to do is format it so it will show like this...
123 Here Street
There
AA
11111

Basically I want to start a new line at some point in the string. Is this possible to accomplish.

Thanks in advance.

Postnext
Tony LavinioSubject: Formatting String
Author: Tony Lavinio
Date: 17 Jan 2007 05:15 PM
Look at the substring, substring-before and substring-after functions.
You will have to do it in several steps, in each case breaking off the
part you need.

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 18 Jan 2007 09:43 AM
Thanks for you help. I was actually able to find some javascript to help me out but being a newbie to XSL I'm receiving an error and can't figure out what's wrong. Here is the code...

<msxsl:script language="JavaScript" implements-prefix="user">

var vCounter = 0;

function counter() {
vCounter += 1;
return vCounter;
}

function GetNextLine(reportData,pos){
var tmpLen = reportData.length
var tmpString = "";
tmpString= String(reportData.substr(pos,80));
tmpString= tmpString.replace(/ /g,"&#160;");
return tmpString;
}

</msxsl:script>

<xsl:template name="UpdateFields">
<xsl:variable name="start" select="number(0)"/>
<xsl:variable name="increment" select="number(80)"/>
<xsl:variable name="end" select="string-length(//business_cbd_info)"/>
<xsl:variable name="report" select="string(//business_cbd_info)"/>
<UD_REPORT_DB>
<xsl:call-template name="loop">
<xsl:with-param name="counter" select="$start"/>
</xsl:call-template>
<!--<xsl:value-of select="//business_cbd_info"/>-->
<!--<xsl:variable name="report" select="string(//business_cbd_info)"/>
<xsl:value-of select="normalize-space(user:FormatReport($report position()))"/>-->
</UD_REPORT_DB>
</xsl:template>

<xsl:template name="loop">
<xsl:param name="counter"/>
<xsl:if test="$counter &lt; $end">
<xsl:value-of select="(user:GetNextLine($report,$counter))"/>
<xsl:call-template name="loop">
<xsl:with-param name="counter" select="$counter + $increment"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 19 Jan 2007 09:26 AM
I figured out how to to pull data using java but I'm having a hard time placing each line on a new line, my code is this...

<msxsl:script language="JavaScript" implements-prefix="user">

var vCounter = 0;

function counter() {
vCounter += 1;
return vCounter;
}

function GetNextLine(reportData,pos){
var tmpLen = reportData.length
var tmpString = "";
tmpString= String(reportData.substr(pos,80));
return tmpString;
}
</msxsl:script>

<xsl:template name="UpdateFields">
<CUST_DATA>
</CUST_DATA>
<Application>
<CO>
<xsl:for-each select="//business_cbd_info[normalize-space()!='']">
<xsl:variable name="start" select="number(0)"/>
<UD_REPORT_DB>
<xsl:call-template name="loop">
<xsl:with-param name="counter" select="$start"/>
</xsl:call-template>
</UD_REPORT_DB>
</xsl:for-each>
</xsl:template>

<xsl:template name="loop">
<xsl:param name="counter" select="0"/>
<xsl:variable name="report" select="string(//business_cbd_info)"/>
<xsl:variable name="end" select="string-length(//business_cbd_info)"/>
<xsl:if test="$counter &lt; $end">
<xsl:value-of select="(user:GetNextLine($report $counter))"/>
<xsl:text>&#xA;</xsl:text>
<xsl:call-template name="loop">
<xsl:with-param name="counter" select="$counter + 80"/>
</xsl:call-template>
</xsl:if>
</xsl:template>


The line <xsl:text>&#xA;</xsl:text> does not work, does anyone know how I can have each line on a new line.

Thanks in advance.

Postnext
Tony LavinioSubject: Formatting String
Author: Tony Lavinio
Date: 19 Jan 2007 11:19 AM
Before I tell you that you don't need JavaScript to do this,
there is some missing information.

How do you want to handle the case where the address includes
information like this:

1. Where the city name is more than one word (e.g. New York)
2. Where the address information includes a street and a PO box
3. What about addresses in Canada or outside the US, where
there might be an extra country name at the end
4. Is there a specific separator that can be used? Or is each
field in the address a certain length?

I can't see how this is supposed to work. It looks like you
are just chopping the string into 80-character chunks.

For what you're using JavaScript for, you can get from the
substring() function in XSLT. My earlier suggestion still
stands - you should use substring-before and substring-after,
and peel off the fields from the end. But the above questions
need to be answered first.

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 19 Jan 2007 12:51 PM
The address was just an example. I'm sorry I should have mentioned this. It's actually a string that is 2752 characters long. It's a report that I'm trying to format. By grabbing every 80 characters I'm able to do this but it doesn't do me any good because I can't seperate each line to start on a new line.

Postnext
Tony LavinioSubject: Formatting String
Author: Tony Lavinio
Date: 21 Jan 2007 05:57 PM
Could you post a sample line, the way it would actually look?

If you have a fixed position for each field, you could output them
like this:
(Assuming street and city were 20 characters each, then followed by
a two-character state and a 5-digit zip)

<xsl:value-of select="normalize-space(substring($row, 1, 20))"/>
<xsl:text>&amp;#10;</xsl:text>
<xsl:value-of select="normalize-space(substring($row, 21, 20))"/>
<xsl:text>&amp;#10;</xsl:text>
<xsl:value-of select="substring($row, 41, 2)"/>
<xsl:text>&amp;#10;</xsl:text>
<xsl:value-of select="substring($row, 43, 5)"/>

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 22 Jan 2007 09:52 AM
The field I'm using is a credit report, the report can be any length of characters, the test report I'm using happens to have 2752 characters. The way we are receiving the report is not formatted properly so I'm trying to format it, I've realized that there should be a line break after every 80 characters so I'm looping through the report and trying to print a line break after ever 80. This is my code...

I'm using javascript to get each line,

<msxsl:script language="JavaScript" implements-prefix="user">

var vCounter = 0;

function counter() {
vCounter += 1;
return vCounter;
}

function GetNextLine(reportData,pos){
var tmpLen = reportData.length
var tmpString = "";
tmpString= String(reportData.substr(pos,80));
return tmpString;
}
</msxsl:script>

<xsl:template name="UpdateFields">
<Application>
<CO>
<xsl:for-each select="//business_cbd_info[normalize-space()!='']">
<xsl:variable name="start" select="number(0)"/>
<UD_CREDIT_REPORT>
<xsl:call-template name="loop">
<xsl:with-param name="counter" select="$start"/>
</xsl:call-template>
</UD_CREDIT_REPORT>
</xsl:for-each>
</CO>
</Application>
</xsl:template>


<xsl:template name="loop">
<xsl:param name="counter" select="0"/>
<xsl:variable name="report" select="string(//business_cbd_info)"/>
<xsl:variable name="end" select="string-length(//business_cbd_info)"/>
<xsl:if test="$counter &lt; $end">
<xsl:value-of select="(user:GetNextLine($report $counter))"/>
<xsl:text>&#10;</xsl:text>
<xsl:call-template name="loop">
<xsl:with-param name="counter" select="$counter + 80"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

This code works great except for the new line, I've tried &#10;, &#xA, &#xD. None of these work.

Postnext
Tony LavinioSubject: Formatting String
Author: Tony Lavinio
Date: 22 Jan 2007 11:22 AM
Get rid of the JavaScript. The counter() function does nothing
for you, and the GetNextLine() is equivalent to
substring($report, $counter, 80)

You didn't say whether your output was text or HTML.
If it's text, for a linebreak, try <xsl:text>&#10;</xsl:text>

If it's HTML, for a linebreak try <br />

If it's XML, for a linebreak try <xsl:text>&amp;#10;</xsl:text>

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 22 Jan 2007 11:41 AM
My output is xml.

I tried all 3 examples you gave for line breaks and none of them worked. <br/> gives me an error and the other two just don't do anything. Any ideas?

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 22 Jan 2007 12:01 PM
Just to be exact, <br/> gives me an error, &#10; does nothing and &amp#10; just prints &amp#10; in the string.

Postnext
Tony LavinioSubject: Formatting String
Author: Tony Lavinio
Date: 22 Jan 2007 04:03 PM
What was the error that <br/> gave?

I'm limited in the help I can give you, since I can't see the
input data, and I can't see the whole transform, and I don't
know exactly what the output is supposed to look like.

If you seriously need more help, you can bundle up the relevant
pieces and send them to stylus-field-report (at) progress.com.

Otherwise, we'll just keep going back and forth in little bits
like this, and I don't want to cause you undue frustration, nor
do I want to drag this out.

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 23 Jan 2007 09:09 AM
I can send you what I have, what I'm trying to do is a little complicated, I'm running a credit report for someone and we send xml files to a company who runs the report for us and sends us the xml back. They send us the credit report back in full in one of the fields but it comes back all jumbled. We are using software that was designed to track everything we do and that includes sending xml to credit, it's all bundled in the software. The software uses FOP. The error I received from the <br/> was from FOP when it was trying to convert the xsl file and it didn't give me an exact error. I'll send you my xsl file along with the xml I'm trying to read from.

Postnext
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 23 Jan 2007 09:11 AM
Just to confirm, you want me to send it to
stylus-field-report@progress.com

Posttop
Tina FleishmanSubject: Formatting String
Author: Tina Fleishman
Date: 23 Jan 2007 02:16 PM
I sent my files, but I also wanted to note that when I use the <br/> I looked at my xml file and it's placing everything on the correct line but it's also adding the <br/> in the text, I need the formatting it's giving me without the actual <br/> showing.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.