XSL : unwanted carriage returns/white space

StopBsod

Usenet Archive
Joined
Jan 17, 2004
Messages
4
Reaction score
0
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.
 

Arto V. Viitanen

Usenet Archive
Joined
Oct 2, 2002
Messages
39
Reaction score
0
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.
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
[...]

% 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>
 

StopBsod

Usenet Archive
Joined
Jan 17, 2004
Messages
4
Reaction score
0
Le Tue, 27 Jan 2004 17:23:38 +0100, Patrick TJ McPhee a écrit :
[...]

% 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top