是否可以将属性从 "book1chapter2" 转换为 "chapter2" ?
例如这个节点:
<a myAttribute="part1chapter2" />
应该转化为
<a myAttribute="chapter2" />
我试过:
<xsl:variable name="chapter" select="replace('part1chapter2', 'book1', '')" />
但这会导致编译错误:
ERROR: 'Error checking type of the expression 'funcall(replace, [literal-expr(part1chapter2), literal-expr(part1), literal-expr()])'.'
FATAL ERROR: 'Could not compile stylesheet'
我使用 XSLT 2.0 版。
没有任何库的解决方案将不胜感激:)
编辑:
Java代码,使用javac -g TestXslt.java编译运行;java TestXslt;
public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
Source xslt = new StreamSource(new File("../transform.xslt"));
Transformer transformer = factory.newTransformer(xslt);
Source text = new StreamSource(new File("../input.xml"));
String r = new String();
StreamResult result = new StreamResult(new File("../output.xml"));
transformer.transform(text, result);
}
Java版javac 1.6.0_27