[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

<xsl:copy-of select="." /> removes (or converts) line

Subject: <xsl:copy-of select="." /> removes (or converts) line breaks in text of child nodes.
From: "John Ericson" <john.ericson@xxxxxxxx>
Date: Thu, 15 May 2008 16:28:44 +0200
 <xsl:copy-of select="." /> removes (or converts) line
Hi,

My problem is that my new xml-files produced by XSL removes the line breaks from the text in my <field name="content">....</field> nodes when I use a <xsl:copy-of select="." />. The thing is, my original xml file is produced by mysqldump. It looks fine but in <field name="content">....</field> the exported text has line breaks characters at the end of each line. These are marked ^M in vim btw, and is some kind of extra line break that mysql requires. It looks something like this:

-----
<field name="content">{* DEFAULT FORM LAYOUT / pure CSS *}^M
^M
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; border=&quot;0&quot;&gt;^M
&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;^M
^M
&lt;p&gt;^M
[..]
-----


Now when I XSL transform this file to new files I use <xsl:copy-of select="." /> to export the whole structure as a couple of nodes above the field nodes. Everything exports fine except this text that is slightly changed. The special line breaks have been converted into empty lines. The output looks like this:

-----
		          <field name="value">{* DEFAULT FORM LAYOUT / pure CSS *}



&lt;table cellspacing="0" cellpadding="0" width="100%" border="0"&gt;

&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;



&lt;p&gt;
-----

I need a way to retain the mystic ^M characters because without these I won't get line break when I import the xml in mysql.




The structure of the original xml-file looks like this:


-----
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="sssb">
<table_structure name="cms_content">
<field Field="content_id" Type="int(11)" Null="NO" Key="PRI" Default="" Extra="" />
[..]
</table_structure>
<table_data name="cms_content">
<row>
<field name="content_id">779</field>
<field name="content_name">AnmCfB$l skadedjur</field>
[..]
</row>
<row>
<field name="content_id">780</field>
[..]
</row>
</table_data>
<table_structure name="cms_content_props">
<field Field="content_id" Type="int(11)" Null="YES" Key="MUL" Extra="" />
[..]
</table_structure>
<table_data name="cms_content_props">
<row>
<field name="content_id">780</field>
[..]
</row>
</table_data>
[..]
</database>
</mysqldump>
-----
I used "[..]" signs to note that I cut the file on these places.



My XSL-file looks like this:


-----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="2.0">

<xsl:output method="text" />
<xsl:output method="xml" indent="yes" name="xml" />

<xsl:template match="/">

<!-- If node is table_structure copy it to new file -->
<xsl:for-each select="//table_structure">
	<xsl:variable name="filename" select="concat('tables/',@name,'.xml')" />
	<xsl:value-of select="$filename" />  <!-- Creating  -->
	<xsl:result-document href="{$filename}" format="xml">
		<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<database name="sssb">

<xsl:copy-of select="." />

				<!-- Pick one table_data node after -->
				<xsl:copy-of select="following-sibling::table_data[1]" />
			</database>
		</mysqldump>
	</xsl:result-document>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>
-----

I use Saxon 9.0.0.4N to XSL transform. Thanks for reading!


--
John Ericson, Fast2
Web: http://www.fast2.se


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.