I am generating Excel XML from an XML which has the business data I want to insert. Some of the values in the business data have carraige returns which I want to appear in the Excel app in the end. The Excel XML format maintains carraige returns in its format as , like this: <Data>Line 1 Line 2</Data>
But if I put something like this in my source XML doc, <field>My Value</field>, it gets rendered to the Excel XML like this:
<Data>My
Value</Data>
Excel renders that as a space.
How do I prevent XSLT from unescaping the escaped chars in my source XML?
It's not XSLT that undoes it, but the XML parser.
By the time XSLT, or any XML-related processor, sees the
input, there are no escapes - only translated data.
So and 
 and 
 and a literal linefeed
all look the same.
One thing you can control (if you are using XSLT 2.0) is
how certain characters are output. You can try using
the xsl:character-map feature. You could set it up so
that anywhere you want an explicit you instead write
something else, like &xE00E; to the output, and use the
character map to translate back.
Subject:Keep escaped chars escaped in output Author:Justin Kohlhepp Date:30 Apr 2007 04:09 PM Originally Posted: 30 Apr 2007 04:08 PM
Tony,
Thanks for the help, but I'm afraid I'm still a bit confused. I have my XML source doc and the XSLT I'm going to run it through. In the XSLT I have an xsl:value-of which should output the text of a node in the source doc. Sometimes, in the *result* doc I need the characters so Excel can open it and translate it to a newline in a cell. What do I put in the source doc and XSLT to get this to happen?
I tried to have the source doc have a <node>LINE 1$mynewline;LINE2</node> with a <xsl:character-map><xsl:output-character character="&mynewline;" string="&nbsp;" /></xsl:character-map> in my XSLT, but I got an error saying entity &mynewline; is not declared.
Now I don't know what to do. Having <node>Line 1&#10;Line 2</node> and then an <xsl:value-of select="node" disable-output-escaping="yes"/> will correctly output Line 1 Line 2 in everything but the processor I'm forced to use. :-(