DesignLiquido / xslt-processor

A JavaScript XSLT processor without native library dependencies
GNU Lesser General Public License v3.0
102 stars 31 forks source link

<xsl:copy-of...> generates wrong output for nodes with CDATA #5

Closed james-hu closed 5 years ago

james-hu commented 5 years ago

For example, if the input is like this:

<testsuites>
  <testsuite>
    <testcase name="bla1" time="0" classname="bla1">
      <failure><![CDATA[very long multiline     
    at <anonymous>]]></failure>
    </testcase>
    <testcase name="bla2" time="0" classname="bla2">
      <failure><![CDATA[very long multiline    at <anonymous>]]></failure>
    </testcase>
    <testcase name="bla3" time="2.043" classname="bla3">
    </testcase>
  </testsuite>
</testsuites>

And part of the XSLT is like this:

<xsl:template match="testcase">
    <xsl:copy>
        <xsl:attribute name="name">
            <xsl:value-of select="normalize-space(substring-before(@name, @classname))"/>
        </xsl:attribute>
        <xsl:attribute name="time">
            <xsl:value-of select="number(@time) * 1000"/>
        </xsl:attribute>
        <xsl:attribute name="classname">
            <xsl:value-of select="@classname"/>
        </xsl:attribute>
        <xsl:attribute name="status">
            <xsl:value-of select="@status"/>
        </xsl:attribute>
        <xsl:attribute name="assertions">
            <xsl:value-of select="@assertions"/>
        </xsl:attribute>
        <xsl:copy-of select="failure"/>
        <xsl:copy-of select="skipped"/>
        <xsl:copy-of select="error"/>
        <xsl:copy-of select="system-out"/>
        <xsl:copy-of select="system-err"/>
    </xsl:copy>
</xsl:template>

Then the output would contain only "bla1" with /failure&gt; after ]], and without "bla2" and "bla3:

<testsuites><testsuite><testcase name="bla1" time="0" classname="bla1"><failure><![CDATA[very long multiline    
    at <anonymous>]]>/failure&gt;
    </failure></testcase></testsuite></testsuites>
johanneswilm commented 5 years ago

Hey @james-hu please try to create a patch that solves your problem and then a PR. You are most likely to find the issue that is bothering you much faster than me. Unfortunately no-one is financed to maintain this library.

johanneswilm commented 5 years ago

Hey @james-hu . Please add a full test case to test/xslt.tests.js about this and make a PR about this.

james-hu commented 5 years ago

Sorry mate, I ended up using xsltproc and haven't looked into this issue further.