<xsl:text> doesn't work with CR

P

Paul Verbelen

I have a file with topics. I like to copy them in
another file but want to have some blank lines
between the different topics. I use <xsl:text>
element with as data some blank lines to perform
this. To clarify my question, I have add all the
files required to perform the test.

First question: Why doesn't this works anymore
if I remove the line with " " in the
XSL-file ?

Second question: The [CDATA[ data in the XML-file
is converted in my output file (< becomes &lt;, etc.)
Is there a way to avoid this? I like to keep the
[CDATA[ syntax because it's more readable.


I have following script "test.js":

var myXml = "test.xml";
var myXsl = "test.xsl";
var myOut = "test.out";
var rSourceDoc,rStyleDoc;
var fso, f, ts, s;

rSourceDoc = new ActiveXObject("microsoft.xmldom");
rSourceDoc.async="false";
rSourceDoc.load(myXml);

rStyleDoc = new ActiveXObject("microsoft.xmldom");
rStyleDoc.async="false";
rStyleDoc.load(myXsl);

fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CreateTextFile(myOut);
f = fso.GetFile(myOut);
ts = f.OpenAsTextStream(2);
ts.Write( rSourceDoc.transformNode(rStyleDoc) );
ts.Close( );

Which I run with batch "run.cmd":

cscript test.js

The data file "test.xml" is:

<?xml version="1.0"?>
<topicDb>
<topic>
This is a <b>test</b>
</topic>
<topic><![CDATA[
<H1>Titel</H1>
]]></topic>
</topicDb>

And the xsl file "test.xsl" is:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" version="1.0" indent="yes"/>
<xsl:template match="/">
<xsl:element name="topicDb">
<xsl:for-each select="*/topic">
<xsl:copy-of select="."/>
<xsl:text>
 


</xsl:text>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
 
M

Martin Honnen

Paul Verbelen wrote:

Second question: The [CDATA[ data in the XML-file
is converted in my output file (< becomes &lt;, etc.)
Is there a way to avoid this? I like to keep the
[CDATA[ syntax because it's more readable.

If you want to have the contents of certain elements as CDATA sections
in the output then you have to declare that e.g.
<xsl:eek:utput cdata-section-elements="topic" />
This will however apply to all topic elements in the result tree, not
only to those in the input tree which have CDATA section content.
 
M

Martin Honnen

Paul Verbelen wrote:

Some suggestions not directly related to your questions:
var myXml = "test.xml";
var myXsl = "test.xsl";
var myOut = "test.out";
var rSourceDoc,rStyleDoc;
var fso, f, ts, s;

rSourceDoc = new ActiveXObject("microsoft.xmldom");
rSourceDoc.async="false";
rSourceDoc.load(myXml);

rStyleDoc = new ActiveXObject("microsoft.xmldom");
rStyleDoc.async="false";
rStyleDoc.load(myXsl);

If you want to transform XML to XML then I would do e.g.
var resultDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
rSourceDoc.transformNodeToObject(rStyleDoc, resultDoc);
resultDoc.save(myOut);
instead of using the FileSystemObject.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top