I can't see any reason why contains() should succeed and substring-before() should fail. You don't say how it fails. Please supply a complete example (source document + stylesheet) that demonstrates the problem.
Mike Kay
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2001-07-31
Here's a source file:
<test>
Line 1
Line 2
</test>
It uses $newline for the contains test, but '
' for everything else. If I change the substring-before and substring-after calls to use $newline instead:
<xsl:variable name="next" select="substring-before($text, $newline)"/>
<xsl:variable name="rest" select="substring-after($text, $newline)"/>
I get this:
*
*
*
*
* Line
* 1
*
*
*
* Line
# 2
If I change the concat calls to also use $newline:
<xsl:value-of select="concat('* ', $next, $newline)"/>
such that now everything is using $newline, I get:
*
* * * * Line * 1
* * * * Line # 2
I am using Saxon 6.4.4, by the way (not Instant Saxon).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2001-07-31
Saxon 6.4.3, that is.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a text param with multiple lines (i.e., a string value with embedded newline characters). I also have a global variable defined:
<xsl:variable name="newline" select="'
'"/>
This is working for me:
<xsl:when test="contains($text, $newline)">
But this is not:
<xsl:value-of select="substring-before($text, $newline)/>
When I replace $newline with '
' in the substring-before function, it works.
I also have an ENTITY defined for newline:
<!ENTITY nl "
">
The entity works in general, but this fails, as well:
<xsl:value-of select="substring-before($text, '&nl;')/>
Should these be working, or am I missing a subtlety with how this all works?
I can't see any reason why contains() should succeed and substring-before() should fail. You don't say how it fails. Please supply a complete example (source document + stylesheet) that demonstrates the problem.
Mike Kay
Here's a source file:
<test>
Line 1
Line 2
</test>
Here's a stylesheet that works:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ClassGenerator [ <!ENTITY nl "
"> ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="newline" select="'&nl;'"/>
<xsl:template match="test">
<xsl:variable name="text" select="."/>
<xsl:call-template name="lines">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="lines">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="$text = ''"/>
<xsl:when test="contains($text, $newline)">
<xsl:variable name="next" select="substring-before($text, '
')"/>
<xsl:variable name="rest" select="substring-after($text, '
')"/>
<xsl:value-of select="concat('* ', $next, '
')"/>
<xsl:call-template name="lines">
<xsl:with-param name="text" select="$rest"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('# ', $text, '
')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
It outputs:
*
* Line 1
* Line 2
It uses $newline for the contains test, but '
' for everything else. If I change the substring-before and substring-after calls to use $newline instead:
<xsl:variable name="next" select="substring-before($text, $newline)"/>
<xsl:variable name="rest" select="substring-after($text, $newline)"/>
I get this:
*
*
*
*
* Line
* 1
*
*
*
* Line
# 2
If I change the concat calls to also use $newline:
<xsl:value-of select="concat('* ', $next, $newline)"/>
such that now everything is using $newline, I get:
*
* * * * Line * 1
* * * * Line # 2
I am using Saxon 6.4.4, by the way (not Instant Saxon).
Saxon 6.4.3, that is.