我正在尝试使用XSLT2.0转换来根据项目组将XML文件拆分成更小的文件。为了执行转换,我使用了一个驼峰路由。我的问题是,当运行xslt转换时,生成的文件被保存在“路由”之外。
因此,例如,给定以下驼峰路由:
from("{{input.endpoint}}")
.to("xslt:xslts/ics/MappingMapTostudents.xslt?saxon=true")
.to("{{output.endpoint}}");
我期望在{output.endpoint}文件夹中创建生成的xml文件。不幸的是,saxon将文件保存在可执行文件(camel应用程序)所在的根文件夹中。如何将文件保存到{{output.endpoint}}或更高版本,并将其传递到以下终结点?
下面是一个XML示例:
<?xml version="1.0" encoding="UTF-8"?>
<class>
<students>
<student>
<firstname>Albert</firstname>
<group>A</group>
</student>
<student>
<firstname>Isaac</firstname>
<group>A</group>
</student>
<student>
<firstname>Leonardo</firstname>
<group>B</group>
</student>
<student>
<firstname>Enrico</firstname>
<group>B</group>
</student>
<student>
<firstname>Marie</firstname>
<group>C</group>
</student>
<student>
<firstname>Rosalind</firstname>
<group>C</group>
</student>
<student>
<firstname>Ada</firstname>
<group>D</group>
</student>
</students>
</class>
XSLT转换:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:grp="http://www.altova.com/Mapforce/grouping" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="grp xs fn">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:function name="grp:var2_function">
<xsl:param name="var1_param" as="node()"/>
<xsl:for-each select="$var1_param/student">
<xsl:sequence select="fn:string(group)"/>
</xsl:for-each>
</xsl:function>
<xsl:template match="/">
<xsl:for-each-group select="class/students" group-by="grp:var2_function(.)">
<xsl:variable name="var3_resultof_grouping_key" as="xs:string" select="current-grouping-key()"/>
<xsl:result-document href="{fn:concat($var3_resultof_grouping_key, '.xml ')}" encoding="UTF-8">
<class>
<xsl:for-each select="(current-group()/student)[(fn:string(group) = $var3_resultof_grouping_key)]">
<students>
<student>
<firstname>
<xsl:sequence select="fn:string(firstname)"/>
</firstname>
<group>
<xsl:sequence select="$var3_resultof_grouping_key"/>
</group>
</student>
</students>
</xsl:for-each>
</class>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
发布于 2019-03-15 04:24:27
我对Apache-Camel知之甚少,不幸的是,在StackOverflow上关于这项技术的问题似乎没有很高的成功率。
http://camel.apache.org/xslt.html的文档没有提供关于如何设置基本输出URI的线索,Saxon使用它来解析出现在xsl:result-document/@href
中的任何相对URI。
想到的最简单的方法是将一个参数传递给转换,该参数的值是输出目录的绝对路径:
<xsl:param name="outDir" as="xs:string"/>
...
<xsl:result-document
href="file:///{$outDir}{$var3_resultof_grouping_key}.xml"/>
但了解Apache Camel的人可能会提出一个更优雅的解决方案。
https://stackoverflow.com/questions/55168069
复制相似问题