• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Regex Line Break Oddness

Valorous Hero ,
Jul 01, 2010 Jul 01, 2010

Copy link to clipboard

Copied

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?

TOPICS
Advanced techniques

Views

778

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2010 Jul 12, 2010

Copy link to clipboard

Copied

I'm not having much luck suggesting to people they google stuff today, but I'll try it on you, Ian.

I've not come across this myself, but when I googled on "xsl not preserving line breaks in attribute names", I came up with some stuff which looked like it might be worth investigating?

That <xsl:preserve-space elements="text"/> thing looks promising?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 12, 2010 Jul 12, 2010

Copy link to clipboard

Copied

LATEST

Adam Cameron. wrote:

That <xsl:preserve-space elements="text"/> thing looks promising?

--

Adam

Yup, I thought so too, when I found it myself.  But it had no affect on the output.

What made this particularly wierd for me, is that different tools got different results.  I ended up thinking outside the box.  When I got the XML from the tool and applied the transformation with ColdFusion I get the undersiable results I discussed above.

Instead, I took the XML file from the tool and used ColdFusion to modify it to include a stylesheet declaration directly in the XML then returned that to the browser.  That allowed me to run it in I.E. and get the output as I desired.

But I am sitll curious why there was such inconsistancy between results.


If you care, I am now looking for help on a new XML and ColdFusion question

http://forums.adobe.com/thread/678689

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation