<xsl:text> doesn't work with CR

Discussion in 'XML' started by Paul Verbelen, Jun 26, 2006.

  1. 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>
     
    Paul Verbelen, Jun 26, 2006
    #1
    1. Advertising

  2. 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.





    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 26, 2006
    #2
    1. Advertising

  3. 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.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 26, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Owen
    Replies:
    1
    Views:
    472
    Natty Gur
    Jul 24, 2003
  2. Replies:
    1
    Views:
    3,690
    A. Bolmarcich
    May 27, 2005
  3. MZ
    Replies:
    7
    Views:
    874
    Ed Mullen
    Mar 17, 2008
  4. Tilman
    Replies:
    0
    Views:
    440
    Tilman
    Mar 19, 2008
  5. rigo
    Replies:
    0
    Views:
    190
Loading...

Share This Page