使用XSLT和Java替换XML节点文本?

XML文件 –

  2009-1 3-11-2011 2:55:0 Book XXX   2009-2 3-12-2011 2:55:0 Song XXX   

我想替换特定文本。 例如; 对于Cid 2009-1,我想更新/更改相应的评论XXX到YYY。 这两个值都基于我的java代码将传递的参数。 以下是XSLT文件 –

                 

这是Java代码的一部分

  String cid = "2009-1"; String comm = "YYY"; TransformerFactory factory = TransformerFactory.newInstance(); Source xslt = new StreamSource(new File("loc1.xslt")); Transformer transformer = factory.newTransformer(xslt); transformer.setParameter("ciName",cid); transformer.setParameter("coName",comm); Source text = new StreamSource(new File("Comments.xml")); transformer.transform(text, new StreamResult(new File( "Comments1.xml"))); 

错误 –

 ERROR: 'Premature end of file.' ERROR: 'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Premature end of file.' Excep...... 

此外,我无法编辑/替换/更改相应的评论…任何帮助……? 提前致谢。

使用像Saxon 9这样的XSLT 2.0处理器

               

使用XSLT 1.0,不允许在匹配模式中使用变量或参数引用,因此您需要使用