Hi,
Timely that CSV is being discussed. I have a question that has been stumping me...
I want to be able to output something like:
"text here", "<div><a href=""http://basex.org%22%22%3Etext, and more</a></div>", "text here again"
What's stumping me is being able to double-quote escape the quotation marks that are in my markup. I've tried serializing my elements and then replacing the single quotes of the attributes to double quotes but then when I try to write that to a file (either serializing as text or xml) the tags are escaped to < etc. Here is a bit of what I've tried:
declare option output:indent 'no';
declare variable $txtSer := <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization"> <method value="text"/> </serialization-parameters>; declare variable $xmlSer := <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization"> <method value="xml"/> <indent value="no"/> </serialization-parameters>;
declare variable $outFile := 'out2.csv';
declare variable $xml := <sample><a href="http://basex.org">text, and more text</a></sample>;
declare function local:writeEOL() { file:append($outFile, '
', $txtSer) };
(: Trying to output markup so I can eventually output something like: "text", "<div><a href=""http://basex.org%22%22%3Etext, and more</a></div>", "text" :)
( file:append($outFile, $xml, $txtSer), (: only text of xml out :) local:writeEOL(), file:append($outFile, $xml, $xmlSer), (: xml out but can't escape quotes :) local:writeEOL(), file:append($outFile, serialize($xml), $txtSer), (: tags escaped :) local:writeEOL(), file:append($outFile, serialize($xml, $txtSer), $txtSer), (: only text out :) local:writeEOL(), file:append($outFile, serialize($xml), $xmlSer), (: tags escaped :) local:writeEOL(), file:append($outFile, serialize($xml), $txtSer), (: tags escaped :) local:writeEOL(), file:append($outFile, concat('<![CDATA[', serialize($xml), ']]>'), $xmlSer), (: tags escaped :) local:writeEOL(), file:append($outFile, concat('<![CDATA[', serialize($xml), ']]>'), $txtSer), (: tags escaped :) local:writeEOL(), file:append($outFile, '<,<', $txtSer) (: both are escaped :) )
I don't seem to be able to output the markup in either text or xml mode. What am I doing wrong?
Thanks! Kevin