使用基于节点数的XSLT 1.0拆分XML文件作为计数器值

时间:2017-01-09 05:56:08

标签: xml xslt split

我要求大型XML文件需要根据记录计数器拆分成多个文件,我使用XSLT转换将常量设置为100或1000.

对于整个文件,某些节点值只能使用一次,这些值应该是每个文件中的副本。像标题信息或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>
&#13;
&#13;
&#13;

在上面的文件中,我需要将文件拆分为我设置的计数的AGEvent节点,例如每100个AGEvent节点。如果我在一个文件中有560个AGEvent节点,那么将有6个文件,5个文件中每个100个,最后6个文件将有60个AGEvent节点。

OneTimeForFile节点在输入文件中只能使用一次,因此在第一个AGEvent节点中每个文件应该复制一次。

请帮我写一个完整的XSLT脚本,让我知道任何问题。 我最终搜索网络以找到解决我问题的方法。

我尝试了post here!但没有实现。 您宝贵的时间非常感谢。 提前致谢。

1 个答案:

答案 0 :(得分:0)

使用XSLT 1.0将文件拆分为多个文件的方法只有两种:

  1. 使用供应商扩展程序。为此,我们需要知道您正在使用的XSLT处理器。
  2. 使用多个转换,每个输出文件一个,通常向样式表提供参数,以指示要在每个特定运行中生成哪些分区。为此,我们需要了解更多关于如何调用转换的信息。
相关问题