【发布时间】:2017-05-23 08:19:27
【问题描述】:
我要求一个大型 XML 文件需要根据记录计数器拆分为多个文件,我使用 XSLT 转换将常量设置为 100 或 1000。
对于整个文件,某些节点值只能使用一次,这些值应该是每个文件中的副本。 Like Header 信息或 purchaseOrder 编号
我必须使用 xslt 1.0 版本,在我的中间件系统中没有 2.0 支持解析器。 示例文件如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<ns0:HeaderOffile xmlns:ns0="http://cdpa.com/xix/ALS">
<EPBody>
<EList>
<AgEvent>
<parentId>77777</parentId>
<childId>
<epic>400</epic>
<epic>401</epic>
</childId>
<extensions>
<SExtension>
<epic>400</epic>
<NameValue>
<PName>SERVICE</PName>
<PValue>03</PValue>
</NameValue>
</SExtension>
<OneTimeForFile>
<NameValue>
<PName>ZFIELD1</PName>
<PValue>ROYAL</PValue>
</NameValue>
<NameValue>
<ParameterName>ZFIELD2</ParameterName>
<PValue>GOLD</PValue>
</NameValue>
</OneTimeForFile>
</extensions>
</AgEvent>
<AgEvent>
<parentId>88888</parentId>
<childId>
<epic>300</epic>
<epic>301</epic>
</childId>
<extensions>
<SExtension>
<epic>300</epic>
<NameValue>
<PName>SERVICE</PName>
<PValue>03</PValue>
</NameValue>
</SExtension>
</extensions>
</AgEvent>
<AgEvent>
<parentId>99999</parentId>
<childId>
<epic>200</epic>
<epic>201</epic>
</childId>
<extensions>
<SExtension>
<epic>200</epic>
<NameValue>
<PName>SERVICE</PName>
<PValue>03</PValue>
</NameValue>
</SExtension>
</extensions>
</AgEvent>
</EList>
</EPBody>
</ns0:HeaderOffile>
在上面的文件中,我需要在我设置的计数的 AGEvent 节点处拆分文件,例如每 100 个 AGEvent 节点。如果我在一个文件中有 560 个 AGEvent 节点,那么将有 6 个文件,5 个文件中每个 100 个,最后第 6 个文件将有 60 个 AGEvent 节点。
OneTimeForFile 节点在输入文件中仅可用一次,因此应在第一个 AGEvent 节点中的每个文件中复制一次。
请帮助我编写一个完整的 XSLT 脚本并让我知道任何问题。 我最终在网上搜索以找到解决我问题的方法。
我试过post here!但没有实现。 非常感谢您宝贵的时间。 提前致谢。
【问题讨论】:
-
XSLT 1.0 无法将输入拆分为多个输出文件。如果您的处理器支持,您可以使用 EXSLT
exsl:document扩展指令;否则,您将不得不告诉调用应用程序执行多次转换,每次将参数提高 100。并且您必须找到一种方法将AGEventnodes 的总数传递给调用应用程序。 ——附言我认为与您链接的问题没有任何联系.. -
感谢您的调查。我解决了。