anthony_glenwright
asked on
Replace CRLF with <P> in XSL
I have some XSL like this,
<xsl:copy-of select="$datavalue" />
and datavalue contains carriage return/line feed characters. Is it possible (in XSL) to replace the CRLF with a "<P/>" tag for correct rendering in HTML?
In Visual Basic, I would just do:
mystr=Replace(mystr, chr$(13), "<P/>")
<xsl:copy-of select="$datavalue" />
and datavalue contains carriage return/line feed characters. Is it possible (in XSL) to replace the CRLF with a "<P/>" tag for correct rendering in HTML?
In Visual Basic, I would just do:
mystr=Replace(mystr, chr$(13), "<P/>")
Try the translate(value, from, to) function
ASKER
I tried translate - it doesn't work the way you would think, since it replaces matching characters from the second string with those in the same position in the 3rd string...
i.e. translate ("AAA", "AZZ", "RRR") = "RAA"
strange that they would even make up such a strange function...
PS: Are you the minna that I know?
i.e. translate ("AAA", "AZZ", "RRR") = "RAA"
strange that they would even make up such a strange function...
PS: Are you the minna that I know?
I do that by a server-side VBScript script. If there'll be no XSLT solution, I'll post it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Minna and Anthony,
FYI about the xPath function 'translate()', check out this page:
http://www.w3.org/TR/xpath#function-translate
-------------------------- --------
The translate function returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string. For example, translate("bar","abc","ABC ") returns the string BAr. If there is a character in the second argument string with no character at a corresponding position in the third argument string (because the second argument string is longer than the third argument string), then occurrences of that character in the first argument string are removed. For example, translate("--aaa--","abc-" ,"ABC") returns "AAA". If a character occurs more than once in the second argument string, then the first occurrence determines the replacement character. If the third argument string is longer than the second argument string, then excess characters are ignored.
NOTE: The translate function is not a sufficient solution for case conversion in all languages. A future version of XPath may provide additional functions for case conversion.
-------------------------- --------
Mostly I've used it to convert from one case to another, so for example I'll have something like this at the very top of my XSL file:
<!DOCTYPE xsl:stylesheet [
<!ENTITY indenthtml "no">
<!-- NOTE: Change indenthtml indent to "yes" for debugging generated HTML and "no" for code optimized for production -->
<!ENTITY nbsp " ">
<!ENTITY bgcolor1 "#FFFFFF"> <!-- white -->
<!ENTITY bgcolor2 "#CC6600"> <!-- dark orange -->
<!ENTITY bgcolor3 "#FFCC66"> <!-- light orange -->
<!ENTITY txtcolor1 "#000000"> <!-- black -->
<!ENTITY compWidth "670"> <!-- Component width / width of table that holds the component -->
<!ENTITY lowerCase "abcdefghijklmnopqrstuvwxy z">
<!ENTITY upperCase "ABCDEFGHIJKLMNOPQRSTUVWXY Z">
]>
Then later in the document I could do something like:
<td width="16%" valign="top" class="MOIDocText">
<xsl:value-of select="translate(LIMITS/D ETAIL[1]/T YPE, '&lowerCase;', '&upperCase;')"/>
<xsl:text> </xsl:text >
</td>
FYI about the xPath function 'translate()', check out this page:
http://www.w3.org/TR/xpath#function-translate
--------------------------
The translate function returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string. For example, translate("bar","abc","ABC
NOTE: The translate function is not a sufficient solution for case conversion in all languages. A future version of XPath may provide additional functions for case conversion.
--------------------------
Mostly I've used it to convert from one case to another, so for example I'll have something like this at the very top of my XSL file:
<!DOCTYPE xsl:stylesheet [
<!ENTITY indenthtml "no">
<!-- NOTE: Change indenthtml indent to "yes" for debugging generated HTML and "no" for code optimized for production -->
<!ENTITY nbsp " ">
<!ENTITY bgcolor1 "#FFFFFF"> <!-- white -->
<!ENTITY bgcolor2 "#CC6600"> <!-- dark orange -->
<!ENTITY bgcolor3 "#FFCC66"> <!-- light orange -->
<!ENTITY txtcolor1 "#000000"> <!-- black -->
<!ENTITY compWidth "670"> <!-- Component width / width of table that holds the component -->
<!ENTITY lowerCase "abcdefghijklmnopqrstuvwxy
<!ENTITY upperCase "ABCDEFGHIJKLMNOPQRSTUVWXY
]>
Then later in the document I could do something like:
<td width="16%" valign="top" class="MOIDocText">
<xsl:value-of select="translate(LIMITS/D
<xsl:text> </xsl:text
</td>
ASKER
Thanks all - I ended up solving a different way (at the database end), but MFlint's answer is a solution...