0

I have an input xml suppose of the form

<A>
  <B></B>
  <!---->
  <C></C>
</A>

I am using XSL to transform this XML, but when I parse this XML I am getting below error message

"Error serializing file java.lang.ArrayIndexOutOfBoundsException: -1 Base Exception"

I have already included below command in my XSL, still getting the same error

<xsl:template match="comment()"/>

Please help!

TIA :)

4

1 回答 1

1

尝试:

  <xsl:template match="comment()[.='']"/>

示例 XML:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <!---->
  <!--above comment line should be deleted-->
  <foo>
    <!--fooo data-->
    <foobar/>
  </foo>
</root>

输入 XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
  <xsl:template match="comment()[.='']"/>
</xsl:stylesheet>

输出:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <!--above comment line should be deleted-->
  <foo>
    <!--fooo data-->
    <foobar />
  </foo>
</root>
于 2013-01-10T09:40:52.543 回答