I have an XML file created by a tool I use. I am attempting to apply an
XSLT transformation to this file to create a nice report. I am finding
some strange behavior when I do so.
There is an attribute that contains carriage returns and line feeds.
This is desirable and I wish to include them in my output. Everything I
read about XML says this just fine. But when I process the XML with the
XSLT at least three out of five tools strip these line break characters.
Here is an example of the behavior using ColdFusion to manipulate the XML.
<cfsavecontent variable="toDoListXML"><?xml version="1.0"
encoding="windows-1252" ?>
|<?xml-stylesheet type="text/xsl" href="status-report.xsl"?>
<TODOLIST>
<TASK COMMENTS="Sent e-mail asking if this task can be removed.
Removed Schedule Task per Julie's authorization.
"/>
</TODOLIST>
</cfsavecontent>
<cfset toDoListOBJ = xmlParse(toDoListXML)>
<cfset taskNode = toDoListOBJ.toDoList.task[1].xmlAttributes['COMMENTS']>
<cfdump var="#toDoListOBJ.toDoList.Task[1]#">
<cfset comment = toDoListOBJ.toDoList.task[1].xmlAttributes["COMMENTS"]>
<cfoutput>
<pre>#comment#</pre>
<cfloop from="1" to="#len(taskNode)#" index="char">
#mid(comment,char,1)#[#asc(mid(comment,char,1))#]
</cfloop>
</cfoutput>
<cfset commentSegment = refind('COMMENTS="Sent
e-mail[^"]*"',toDoListXML,1,true)>
<cfset comment = mid(toDoListXML,commentSegment.pos[1],commentSegment.len[1])>
<cfset comment = reReplace(comment,'COMMENTS="(Sent e-mail[^"]*)"','\1','ONE')>
<cfoutput>
<pre>#comment#</pre>
<cfloop from="1" to="#len(taskNode)#" index="char">
#mid(comment,char,1)#[#asc(mid(comment,char,1))#]
</cfloop>
</cfoutput>
|
As one can see in the first part of the output where the xml had been
parsed into a ColdFusion xml object, the line breaks are gone. In the
second part where raw xml text is output shows that they are there.
Interestingly if I directly connect the style sheet to the xml and
open it in a browser, Firefox, Chrome and Opera all transform it the
same as CF stripping the line breaks. IE and an XML Viewer by
MindFusion do it the way I expect it to by done, leaving the breaks in.
Unfortunatly IE does not like my CSS formating applied to the <pre> tag.
Other then just breaking down and working this in IE does anybody have
any other thoughs on what is going on here?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:335021
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm