XSL : unwanted carriage returns/white space

Discussion in 'XML' started by StopBsod, Jan 26, 2004.

  1. StopBsod

    StopBsod Guest

    Hello group,

    I use XSLT to output a unix shell script based on the content of an XML
    file :

    The XSLT :

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:eek:utput method="text"/>
    <xsl:template name="haut" match="/rhythmdb">

    #!/bin/bash
    cd /pub/html/zicmu2/links

    <xsl:for-each select="entry">
    <xsl:sort select="location"/>
    ln -s "<xsl:value-of select="substring-after(location,'file://')"/>"
    <xsl:choose>
    <xsl:when test="starts-with(location,'file:///pub/joe/misc')">
    "<xsl:value-of select="substring(location, 22)"/>"
    </xsl:when>
    <xsl:eek:therwise>
    "<xsl:value-of select="substring(location, 19)"/>"
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    After conversion (with xsltproc/libxml)

    #!/bin/bash
    cd /pub/html/zicmu2/links


    ln -s "data1"

    "to_data1"

    ln -s "data2"

    "to data2"


    So I have many unwanted carriage returns/whitspaces. (it follows the
    indentation of my .XSL...)

    I googled around and saw <xsl:text> ?

    Didn't work 'cause my XML file has unsupported char.

    Help Welcomed.

    Thks.
     
    StopBsod, Jan 26, 2004
    #1
    1. Advertising

  2. >>>>> "StopBsod" == StopBsod <> writes:

    StopBsod> After conversion (with xsltproc/libxml)

    StopBsod> #!/bin/bash cd /pub/html/zicmu2/links


    StopBsod> ln -s "data1"

    StopBsod> "to_data1"

    StopBsod> ln -s "data2"

    StopBsod> "to data2"

    I suggest you use concat() function. With it (and an explict $newline
    variable) you can create the lines as you like.


    --
    Arto V. Viitanen
    University of Tampere, Department of Computer Sciences
    Tampere, Finland http://www.cs.uta.fi/~av/
     
    Arto V. Viitanen, Jan 27, 2004
    #2
    1. Advertising

  3. In article <>,
    StopBsod <> wrote:

    [...]

    % So I have many unwanted carriage returns/whitspaces. (it follows the
    % indentation of my .XSL...)

    % I googled around and saw <xsl:text> ?

    This is what you want to use. If you have non-whitespace text in a template,
    then all the text in the template, including all the white space, gets
    copied to the result tree. If you wrap all your non-whitespace text in
    xsl:text elements, then only the text in the xsl:text elements, along with
    text generated by other xsl elements, will be copied.

    % Didn't work 'cause my XML file has unsupported char.

    I expect you put one of your value-ofs inside a text element. This works
    the way you want it to:


    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:eek:utput method="text"/>
    <xsl:template name="haut" match="/rhythmdb">

    <xsl:text>#!/bin/bash
    cd /pub/html/zicmu2/links
    </xsl:text>
    <xsl:for-each select="entry">
    <xsl:sort select="location"/>
    <xsl:text>ln -s "</xsl:text>
    <xsl:value-of select="substring-after(location,'file://')"/>
    <xsl:text>" "</xsl:text>
    <xsl:choose>
    <xsl:when test="starts-with(location,'file:///pub/joe/misc')">
    <xsl:value-of select="substring(location, 22)"/>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:value-of select="substring(location, 19)"/>
    </xsl:eek:therwise>
    </xsl:choose>
    <xsl:text>"
    </xsl:text>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Jan 27, 2004
    #3
  4. StopBsod

    StopBsod Guest

    Le Tue, 27 Jan 2004 17:23:38 +0100, Patrick TJ McPhee a écrit :

    > In article <>,
    > StopBsod <> wrote:
    >
    > [...]
    >
    > % So I have many unwanted carriage returns/whitspaces. (it follows the
    > % indentation of my .XSL...)
    >
    > % I googled around and saw <xsl:text> ?
    >
    > This is what you want to use. If you have non-whitespace text in a template,
    > then all the text in the template, including all the white space, gets
    > copied to the result tree. If you wrap all your non-whitespace text in
    > xsl:text elements, then only the text in the xsl:text elements, along with
    > text generated by other xsl elements, will be copied.
    >
    > % Didn't work 'cause my XML file has unsupported char.
    >
    > I expect you put one of your value-ofs inside a text element. This works
    > the way you want it to:
    >
    >
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    > <xsl:eek:utput method="text"/>
    > <xsl:template name="haut" match="/rhythmdb">
    >
    > <xsl:text>#!/bin/bash
    > cd /pub/html/zicmu2/links
    </xsl:text>
    > <xsl:for-each select="entry">
    > <xsl:sort select="location"/>
    > <xsl:text>ln -s "</xsl:text>
    > <xsl:value-of select="substring-after(location,'file://')"/>
    > <xsl:text>" "</xsl:text>
    > <xsl:choose>
    > <xsl:when test="starts-with(location,'file:///pub/joe/misc')">
    > <xsl:value-of select="substring(location, 22)"/>
    > </xsl:when>
    > <xsl:eek:therwise>
    > <xsl:value-of select="substring(location, 19)"/>
    > </xsl:eek:therwise>
    > </xsl:choose>
    > <xsl:text>"
    </xsl:text>
    > </xsl:for-each>
    > </xsl:template>
    > </xsl:stylesheet>



    Thanks !

    Works just perfectly. I'll study the code now ;-)

    M.
     
    StopBsod, Jan 27, 2004
    #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. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,924
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,692
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    1,038
    Steve Lamb
    Oct 23, 2003
  4. Ben C
    Replies:
    6
    Views:
    2,175
    Leif K-Brooks
    Jan 28, 2007
  5. Steve Anderson
    Replies:
    3
    Views:
    258
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page