Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enforce line break in xsl

Status
Not open for further replies.

anyideas

Programmer
May 2, 2002
127
0
0
GB
hi

I have an xml element whos value is loaded from a database and may contain a vbcrlf.

When xsl renders it, the vbcrlf is ignored and everything is written on one line in the browser.

Does anyone hane any ideas on how to enforce a line break when the break is in the xml element?

Thanks
Mark
 
Hello Chip

I've tried that and it's no good. Thanks for trying!

if I post the post could someone have a look? theres 3 files:

start.asp
xml.asp
xsl.xsl

Just put the three in the same directory and run start.asp

cheers, heres the code...

start.asp
-----------

<html>
<head></head>
<body onload=&quot;doGetEventDetais()&quot;>

<script LANGUAGE=&quot;javascript&quot;>

function doGetEventDetais(){

//Create a xml document object, and load server's response
var source = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
var xsl = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
source.async = false;
xsl.async = false;

if( !source.load(&quot;xml.asp&quot;) )
{
alert( source.parseError.reason );
alert( source.parseError.linepos );
alert( source.parseError.srcText );
alert( source.text );
return;
}

if( !xsl.load(&quot;xsl.xsl&quot;) )
alert( xsl.parseError.reason );

window.spanii.innerHTML = source.transformNode(xsl);

}

</script>

<span name=&quot;spanii&quot; id=&quot;spanii&quot;></span>

</body>
</html>

-----------------------------------------------------------

xml.asp
---------

<%@ Language=VBScript %>
<%
dim strXML
strXML = strXML & &quot;<Event>&quot;
strXML = strXML & &quot;<Notes><![CDATA[abcde &quot;& vbcrlf &&quot;jdsfskjf]]></Notes>&quot;
strXML = strXML & &quot;</Event>&quot;

Response.Write(strXML)
%>

-----------------------------------------------------------

xsl.xsl
---------

<xsl:stylesheet xmlns:xsl=&quot; language=&quot;VBScript&quot;>

<xsl:template match=&quot;/&quot;><xsl:apply-templates select=&quot;*&quot;/></xsl:template>

<xsl:template match=&quot;Event&quot;>
<table width=&quot;100%&quot;>
<tr>
<td bgcolor=&quot;#F5F7FB&quot;><b>Notes</b></td>
</tr>
<tr>
<td bgcolor=&quot;#F5F7FB&quot;><xsl:value-of select=&quot;Notes&quot;/></td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>

-----------------------------------------------------------

Cheers again

Mark
 
<xsl:text><xsl:value-of select=&quot;Notes&quot;/></xsl:text>

this should work. if it doesn't then use the proper xsl namespace of


instead of which is about 4 years out of date.

you might also want to look at <xsl:preserve-space elements=&quot;Notes&quot;/> which would go in the top level of your xsl doc.
 
Hello Chip

I tried the following:
<xsl:text><xsl:value-of select=&quot;Notes&quot;/></xsl:text>

but an error happened:
Keyword xsl:text may not contain xsl:value-of.

That was using the following code:

xsl.xsl
--------

<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;<xsl:template match=&quot;/&quot;>
<xsl:apply-templates select=&quot;*&quot;/>
</xsl:template>
<xsl:template match=&quot;Event&quot;>

<table width=&quot;100%&quot;>
<tr>
<td bgcolor=&quot;#F5F7FB&quot;>
<b>Notes</b>
</td>
</tr>
<tr>
<td bgcolor=&quot;#F5F7FB&quot;>
<xsl:text><xsl:value-of select=&quot;Notes&quot;/></xsl:text>
</td>
</tr>
</table>

</xsl:template>
</xsl:stylesheet>

Thanks for help, out of interest do you think the error might have some to do with the following line in start.asp:

window.spanii.innerHTML = source.transformNode(xsl);

cheers for your help.

Mark
 
If an item contains CrLf or groups of spaces that you want to preserve then enclose it in the HTML <pre>...</pre> tags.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top