使用//迭代节点集中的子体时出现意外结果



在我使用标准JDK的简单XSLT转换中,当使用//快捷键时,我得到了意想不到的结果。

package my.xslt.test;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class IssuePresenter {
public static void main(String[] args) throws Exception {
StringBuilder xslt = new StringBuilder();
xslt.append("<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
xslt.append("                xmlns:exsl='http://exslt.org/common'");
xslt.append("                exclude-result-prefixes='exsl'");
xslt.append("                version='1.0'>");
xslt.append("<xsl:output indent='yes' omit-xml-declaration='yes'/>");
xslt.append("<xsl:variable name='tree'>");
xslt.append("  <entry level='0'>");
xslt.append("    <entry level='1'/>");
xslt.append("  </entry>");
xslt.append("</xsl:variable>");
xslt.append("<xsl:template match='/'>");
xslt.append("  <a><xsl:copy-of select='exsl:node-set($tree)//entry'/></a>");
xslt.append("  <b><xsl:copy-of select='exsl:node-set($tree)/descendant::entry'/></b>");
xslt.append("</xsl:template>");
xslt.append("</xsl:stylesheet>");
StringWriter writer = new StringWriter();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Templates templates = transformerFactory.newTemplates(new StreamSource(new StringReader(xslt.toString())));
Transformer transformer = templates.newTransformer();
transformer.transform(new StreamSource(new StringReader("<document/>")), new StreamResult(writer));
System.out.println(writer);
}
}

我期望<a><b>相同。是bug还是我遗漏了什么?

<a>
<entry level="1"/>
</a><b>
<entry level="0">
<entry level="1"/>
</entry>
<entry level="1"/>
</b>

此问题已被确认为JDK错误,可以在此处跟踪https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8265134

相关内容

  • 没有找到相关文章

最新更新