You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Erik Dasque <ed...@silverstream.com> on 2000/03/22 20:41:11 UTC
newline function
Hi,
I have something that used to work with Xalan 0.19.5 (I believe) and works
with the Stylus editor. It behaves differently with Xalan 0.20.0 :
XML :
<?xml version="1.0" standalone="yes"?>
<DOCUMENT DOC_ID="502" DateCreated="03/22/2000 11:27"
MimeType="text/plain" Version="0">
<Author AUTHOR_ID="2">
<FirstName>Erik</FirstName>
<LastName>Dasque</LastName>
<EMail>edasque@silverstream.com</EMail>
<Title>Technical Marketing Mgr</Title>
<Organization>SilverStream Software</Organization>
</Author>
<TXT_BODY>123
12s
1></TXT_BODY>
<LOCALE><![CDATA[en]]></LOCALE>
<TITLE><![CDATA[sfdgdf]]></TITLE>
</DOCUMENT>
Extract from the XSL :
<xsl:template name="nl2br">
<!-- import $StringToTransform -->
<xsl:param name="StringToTransform"/>
<xsl:choose>
<!-- string contains newline -->
<xsl:when test="contains($StringToTransform,'
')">
<!-- output substring that comes before the first newline -->
<!-- note: use of substring-before() function means -->
<!-- $StringToTransform will be treated as a
g, -->
<!-- even if it is a node-set or result tree
gment. -->
<!-- So hopefully $StringToTransform is really a
tring! -->
<xsl:value-of
select="substring-before($StringToTransform,'
')"/>
<!-- output a <br> tag instead of newline -->
<br/>
<!-- repeat for the remainder of the original
string -->
<xsl:call-template name="nl2br">
<xsl:with-param name="StringToTransform">
<xsl:value-of
select="substring-after($StringToTransform,'
')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!-- string does not contain newline, so just output
it -->
<xsl:otherwise>
<xsl:value-of select="$StringToTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
AND :
<xsl:template match="TXT_BODY">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<!-- Used to replace newlines with <BR> tags -->
<xsl:call-template name="nl2br">
<xsl:with-param
name="StringToTransform" select="."/>
</xsl:call-template>
</td>
</tr>
</table>
</td>
</tr>
</xsl:template>
-----------------
I am expecting the following result but I am not getting any <BR/>s ?
[following is an output from Stylus XSL engine]
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>123
<br>
<br>12s
<br>
<br>1
</td>
</tr>
</table>
</td>
</tr>
What do you think ?
Ed.
newline function
Posted by Erik Dasque <ed...@silverstream.com>.
Hi,
I have something that used to work with Xalan 0.19.5 (I believe) and works
with the Stylus editor. It behaves differently with Xalan 0.20.0 :
XML :
<?xml version="1.0" standalone="yes"?>
<DOCUMENT DOC_ID="502" DateCreated="03/22/2000 11:27"
MimeType="text/plain" Version="0">
<Author AUTHOR_ID="2">
<FirstName>Erik</FirstName>
<LastName>Dasque</LastName>
<EMail>edasque@silverstream.com</EMail>
<Title>Technical Marketing Mgr</Title>
<Organization>SilverStream Software</Organization>
</Author>
<TXT_BODY>123
12s
1></TXT_BODY>
<LOCALE><![CDATA[en]]></LOCALE>
<TITLE><![CDATA[sfdgdf]]></TITLE>
</DOCUMENT>
Extract from the XSL :
<xsl:template name="nl2br">
<!-- import $StringToTransform -->
<xsl:param name="StringToTransform"/>
<xsl:choose>
<!-- string contains newline -->
<xsl:when test="contains($StringToTransform,'
')">
<!-- output substring that comes before the first newline -->
<!-- note: use of substring-before() function
-->
<!-- $StringToTransform will be treated as a
g, -->
<!-- even if it is a node-set or result tree
gment. -->
<!-- So hopefully $StringToTransform is really a
string! -->
<xsl:value-of
select="substring-before($StringToTransform,'
')"/>
<!-- output a <br> tag instead of newline -->
<br/>
<!-- repeat for the remainder of the original
string -->
<xsl:call-template name="nl2br">
<xsl:with-param name="StringToTransform">
<xsl:value-of
select="substring-after($StringToTransform,'
')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!-- string does not contain newline, so just
output it -->
<xsl:otherwise>
<xsl:value-of select="$StringToTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
AND :
<xsl:template match="TXT_BODY">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<!-- Used to replace newlines with <BR> tags -->
<xsl:call-template name="nl2br">
<xsl:with-param
name="StringToTransform" select="."/>
</xsl:call-template>
</td>
</tr>
</table>
</td>
</tr>
</xsl:template>
-----------------
I am expecting the following result but I am not getting any <BR/>s ?
[following is an output from Stylus XSL engine]
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>123
<br>
<br>12s
<br>
<br>1
</td>
</tr>
</table>
</td>
</tr>
What do you think ?
Ed.