我们的应用程序将其配置的一部分导出为一组bean。配置的每个部分都包含多个类似的项目,每个项目都有一个名称
理想情况下,开发人员会分别导出每个项目,并以有意义的名称将它们检入我们的源代码管理。不幸的是,一些开发人员很懒,将整个列表导出为单个文件,并检查类似'export.xml'的内容:(
我想处理这样的bean文件,最后每个bean都有一个文件。以前有人做过这样的事吗?我想我正在看xslt,但我不知道如何最终得到多个输出文件。
为了额外的功劳:),我可以使用bean中指定属性的值来命名文件。
答案 0 :(得分:0)
查看" Splitter"图案:
http://www.eaipatterns.com/Sequencer.html
Apache Camel实现了这个:
http://camel.apache.org/splitter.html
......和Spring Integration一样:
...和JBoss Fuse:
选择你最喜欢的......
答案 1 :(得分:0)
回答我自己的问题。
可以使用以下XLST样式表在XSLT 2.0中完成:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/beans/bean" xml:space="preserve">
<xsl:result-document href='file{translate(normalize-space(./property[@name="name"])," ", "_")}.xml'
doctype-public="-//SPRING//DTD BEAN//EN"
doctype-system="http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<xsl:copy-of select="." />
</beans>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
这使用“name”属性的值来构造文件名。