spacing in XSLT, return char after each line? / last record separator removal

Discussion in 'XML' started by bjam, Apr 28, 2005.

  1. bjam

    bjam Guest

    Hi,

    I am hoping someone can help with this I am assuming it is pretty
    basic but I don't see anything that jumps out at me at how to do this.
    Is there a way to have all the items output from the style sheet appear
    as a single line with no return chars?? When executing the following
    style sheet, how can I concatenate the values together in a single
    line, in this case a single line would be how the browser displays
    this, but I want the general text output to be a single line as well.
    Basically is there a way to have all these lines concatenated together
    when being outputted by the style sheetinstead of having a return
    character after each line? Also, is there a way to have the xslt know
    to not produce the last pipe on the line??? Maybe some type of
    following-sibling??
    Thanks in advance for your help. I appreciate it.

    Desired Ouptput (note last data element does not have pipe)
    ================

    <html xmlns:rep="http://localhost:7001/reporting"><body><table
    border="0"><tr><td>11006732.908899993|</td><td>7941634.67709|</td><td>3065098.23181004|</td><td>3065098.23181004|</td><td>11006732.908899993</td></tr></table></body></html>


    The output I am getting
    ( returns in output and last data element does have pipe)
    =======================

    $ test_XSLT.pl ( this is just my perl code that translates XSLT)

    <html xmlns:rep="http://localhost:7001/reporting"><body><table
    border="0"><tr>
    <td>11006732.908899993|</td>
    <td>7941634.67709|</td>
    <td>3065098.23181004|</td>
    <td>3065098.23181004|</td>
    <td>11006732.908899993|</td>
    </tr></table></body></html>

    END OF TEST ./test_XSLT.pl


    Style sheet below
    ==================

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rep="http://localhost:7001/reporting">

    <xsl:template match="/">

    <html>
    <body>
    <table border="0">
    <tr>

    <xsl:apply-templates
    select="/rep:FrontPage/rep:frontPageSection/rep:sectionLine"/>

    </tr>
    </table>

    </body>
    </html>

    </xsl:template>

    <xsl:template
    match="/rep:FrontPage/rep:frontPageSection/rep:sectionLine">
    <xsl:apply-templates select="rep:lineName[starts-with(text(),'MARGIN
    EQUITY')]"/>
    <xsl:apply-templates select="rep:lineName[starts-with(text(),'HOUSE
    REQUIREMENTS')]"/>
    <xsl:apply-templates select="rep:lineName[starts-with(text(),'HOUSE
    MARGIN EXCESS/DEFICIT')]"/>
    <xsl:apply-templates select="rep:lineName[starts-with(text(),'CASH
    AVAILABLE')]"/>
    </xsl:template>

    <!-- MARGIN EQUITY -->

    <xsl:template match="rep:lineName[starts-with(text(),'MARGIN
    EQUITY')]">

    <td> <xsl:value-of select="../rep:amountAtDate[text()]"/>
    <xsl:text>|</xsl:text></td>

    </xsl:template>

    <!-- HOUSE REQUIREMENTS-->

    <xsl:template match="rep:lineName[starts-with(text(),'HOUSE
    REQUIREMENTS')]">

    <td> <xsl:value-of select="../rep:amountAtDate[text()]"/>
    <xsl:text>|</xsl:text></td>

    </xsl:template>


    <!-- HOUSE MARGIN EXCESS DEFICIT -->

    <xsl:template match="rep:lineName[starts-with(text(),'HOUSE MARGIN
    EXCESS/DEFICIT')]">

    <td> <xsl:value-of select="../rep:amountAtDate[text()]"/>
    <xsl:text>|</xsl:text></td>

    </xsl:template>

    <!-- CASH AVAILABLE -->

    <xsl:template match="rep:lineName[starts-with(text(),'CASH
    AVAILABLE')]">

    <td> <xsl:value-of select="../rep:amountAtDate[text()]"/>
    <xsl:text>|</xsl:text></td>

    </xsl:template>

    </xsl:stylesheet>


    Data Snippet
    =============

    <rep:FrontPage xmlns:rep="http://localhost:7001/reporting">
    <rep:dateGenerated q="1">Fri Apr 1 14:49:29 2005</rep:dateGenerated>
    <rep:dateGeneratedTimeZone q="1">Eastern Standard Time
    (US/Eastern)</rep:dateGeneratedTimeZone>

    <rep:date q="1">2005-03-31-05:00</rep:date>
    <rep:previousDate q="1">2005-03-30-05:00</rep:previousDate>
    <rep:frontPageSection>
    <rep:sectionName q="1">GLOBAL MARGIN ROLL-UP (USD)</rep:sectionName>
    <rep:sectionLine>
    <rep:lineName q="1">MARGIN EQUITY</rep:lineName>
    <rep:amountAtDate q="0">11006732.908899993</rep:amountAtDate>
    <rep:amountAtPreviousDate
    q="0">-539473.0115977892</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">HOUSE REQUIREMENTS</rep:lineName>
    <rep:amountAtDate q="0">7941634.67709</rep:amountAtDate>
    <rep:amountAtPreviousDate q="0">0</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">HOUSE MARGIN EXCESS/DEFICIT</rep:lineName>
    <rep:amountAtDate q="0">3065098.23181004</rep:amountAtDate>
    <rep:amountAtPreviousDate
    q="0">-539473.011597789</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">CASH AVAILABLE</rep:lineName>
    <rep:amountAtDate q="0">3065098.23181004</rep:amountAtDate>
    <rep:amountAtPreviousDate
    q="0">-539473.011597789</rep:amountAtPreviousDate>
    </rep:sectionLine>
    </rep:frontPageSection>
    <rep:frontPageSection>
    <rep:sectionName q="1">US COMBINED MARGIN PB </rep:sectionName>
    <rep:sectionLine>
    <rep:lineName q="1">LONG MARKET VALUE</rep:lineName>
    <rep:amountAtDate q="0">91617178.1389</rep:amountAtDate>
    <rep:amountAtPreviousDate q="0">0</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">SHORT MARKET VALUE</rep:lineName>
    <rep:amountAtDate q="0">-5365772.36</rep:amountAtDate>
    <rep:amountAtPreviousDate q="0">0</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">CASH BALANCE CR (DR)</rep:lineName>
    <rep:amountAtDate q="0">-75857105.73</rep:amountAtDate>
    <rep:amountAtPreviousDate q="0">0</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">BOND ACCRUED INTEREST</rep:lineName>
    <rep:amountAtDate q="0">612432.86</rep:amountAtDate>
    <rep:amountAtPreviousDate q="0">0</rep:amountAtPreviousDate>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">REG U EXCESS/DEFICIT</rep:lineName>
    </rep:sectionLine>
    <rep:sectionLine>
    <rep:lineName q="1">MARGIN EQUITY</rep:lineName>
    <rep:amountAtDate q="0">11006732.908899993</rep:amountAtDate>
    <rep:amountAtPreviousDate q="0">0</rep:amountAtPreviousDate>
    </rep:sectionLine>
    </rep:frontPageSection>
     
    bjam, Apr 28, 2005
    #1
    1. Advertising

  2. "bjam" <> writes:

    > Hi,
    >
    > I am hoping someone can help with this I am assuming it is pretty
    > basic but I don't see anything that jumps out at me at how to do this.
    > Is there a way to have all the items output from the style sheet appear
    > as a single line with no return chars??


    XSLT never adds any characters on its own. any newlines in the output
    are copied from the source or the stylesheet.
    It isn't clear from your question wheter you are concerned about
    newlines in the generated html (which render as a space in a browser) or
    newlines in the rendered result which come from markup or from a <pre>
    section.

    > When executing the following
    > style sheet, how can I concatenate the values together in a single
    > line, in this case a single line would be how the browser displays
    > this, but I want the general text output to be a single line as well.



    > Basically is there a way to have all these lines concatenated together
    > when being outputted by the style sheetinstead of having a return
    > character after each line?


    > Also, is there a way to have the xslt know
    > to not produce the last pipe on the line??? Maybe some type of
    > following-sibling??



    yes wrap it in
    <xsl:if test="position()!=last()">
    or
    <xsl:if test="following-sibling::*">
    or whatever you need.
     
    David Carlisle, Apr 28, 2005
    #2
    1. Advertising

  3. bjam

    bjam Guest

    David,

    Hi I was interested in new lines in the generated output itself (the
    actual html with tags that is showing not what the browser would
    render), because ultimately I would not be using the html tags and just
    removing them to have the text itself be a single line. Any ideas?
    Also for the last character instead of the pipe it would be great to
    acutally put a newline character in data string. Therefore ultimately
    the data ( once I strip out the html tags would look as follows )


    11006732.908899993|7941634.67709|3065098.23181004|3065098.23181004|11006732.908899993
    (note newline would go here instead of pipe)
     
    bjam, Apr 28, 2005
    #3
  4. bjam

    bjam Guest

    David,

    Hi, thanks again for the positon()!=last() this seems to have worked
    even though I had to play with it a bit. Also, setting the following
    line seemed to fix a lot of the tagging issues I was experiencing

    <xsl:eek:utput method = "text" />
     
    bjam, Apr 28, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lovecreatesbeauty
    Replies:
    1
    Views:
    1,149
    Ian Collins
    May 9, 2006
  2. gert
    Replies:
    20
    Views:
    1,220
  3. Lee Sander
    Replies:
    6
    Views:
    315
    Hendrik van Rooyen
    Jun 1, 2007
  4. Steve Howell
    Replies:
    3
    Views:
    297
    George Sakkis
    Jun 2, 2007
  5. scad
    Replies:
    23
    Views:
    1,216
    Alf P. Steinbach
    May 17, 2009
Loading...

Share This Page