为每个重复的节点创建新的xml
我有一个如下所示的xml。我将创建3个具有相同结构的新xml,并且应该为每个eamployee标记重复相同的结构。下面是完整的xml和我想要的结果。我只为empnum1001放了一个xml,但我会有3个xml为每个重复的节点创建新的xml,xml,xslt,Xml,Xslt,我有一个如下所示的xml。我将创建3个具有相同结构的新xml,并且应该为每个eamployee标记重复相同的结构。下面是完整的xml和我想要的结果。我只为empnum1001放了一个xml,但我会有3个xml <Syncemployee releaseID="9.2"> <ApplicationArea> <Sender> <LogicalID>infor.database.connectiontest</Logica
<Syncemployee releaseID="9.2">
<ApplicationArea>
<Sender>
<LogicalID>infor.database.connectiontest</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-09-17T09:51:03.996Z</CreationDateTime>
<BODID>infor.database.connectiontest:1568713863992:74:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor.test.connection</TenantID>
<AccountingEntityID/>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Replace"/>
</ActionCriteria>
</Sync>
<employee>
<empnum>1001</empnum>
<fullname>John Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
<employee>
<empnum>1002</empnum>
<fullname>Jane Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
<employee>
<empnum>1003</empnum>
<fullname>Tim Bone </fullname>
<dateofhire>2014-01-01</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
</DataArea>
</Syncemployee>
infor.database.connectiontest
外部的
一个错误
2019-09-17T09:51:03.996Z
信息数据库连接测试:1568713863992:74:0
信息测试连接
1001
无名氏
2009-08-28
2019-09-17T11:28:20.287
1002
无名氏
2009-08-28
2019-09-17T11:28:20.287
1003
蒂姆·博恩
2014-01-01
2019-09-17T11:28:20.287
我想为每个重复的雇员标记创建一个新的xml,如下所示
<Syncemployee releaseID="9.2">
<ApplicationArea>
<Sender>
<LogicalID>infor.database.connectiontest</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-09-17T09:51:03.996Z</CreationDateTime>
<BODID>infor.database.connectiontest:1568713863992:74:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor.test.connection</TenantID>
<AccountingEntityID/>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Replace"/>
</ActionCriteria>
</Sync>
<employee>
<empnum>1001</empnum>
<fullname>John Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
</DataArea>
</Syncemployee>
infor.database.connectiontest
外部的
一个错误
2019-09-17T09:51:03.996Z
信息数据库连接测试:1568713863992:74:0
信息测试连接
1001
无名氏
2009-08-28
2019-09-17T11:28:20.287
所以我想得到上面empnum 1001、1002和1003的结果,实际上我想得到3个xml
<Syncemployee releaseID="9.2">
<ApplicationArea>
<Sender>
<LogicalID>infor.database.connectiontest</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-09-17T09:51:03.996Z</CreationDateTime>
<BODID>infor.database.connectiontest:1568713863992:74:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor.test.connection</TenantID>
<AccountingEntityID/>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Replace"/>
</ActionCriteria>
</Sync>
<employee>
<empnum>1001</empnum>
<fullname>John Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
<employee>
<empnum>1002</empnum>
<fullname>Jane Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
<employee>
<empnum>1003</empnum>
<fullname>Tim Bone </fullname>
<dateofhire>2014-01-01</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
</DataArea>
</Syncemployee>
亲爱的Martin,您的代码不适用于我的xml
这是你转变的结果
<?xml version="1.0" encoding="UTF-8"?>
infor.database.connectiontest
External
OnError
2019-09-17T09:51:03.996Z
infor.database.connectiontest:1568713863992:74:0
infor.test.connection
<Syncemployee>
<ApplicationArea>
<Sender>
<LogicalID>infor.database.connectiontest</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-09-17T09:51:03.996Z</CreationDateTime>
<BODID>infor.database.connectiontest:1568713863992:74:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor.test.connection</TenantID>
<AccountingEntityID/>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Replace"/>
</ActionCriteria>
</Sync>
<employee>
<empnum>1001</empnum>
<fullname>John Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
</DataArea>
</Syncemployee>
<Syncemployee>
<ApplicationArea>
<Sender>
<LogicalID>infor.database.connectiontest</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-09-17T09:51:03.996Z</CreationDateTime>
<BODID>infor.database.connectiontest:1568713863992:74:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor.test.connection</TenantID>
<AccountingEntityID/>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Replace"/>
</ActionCriteria>
</Sync>
<employee>
<empnum>1002</empnum>
<fullname>Jane Doe </fullname>
<dateofhire>2009-08-28</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
</DataArea>
</Syncemployee>
<Syncemployee>
<ApplicationArea>
<Sender>
<LogicalID>infor.database.connectiontest</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-09-17T09:51:03.996Z</CreationDateTime>
<BODID>infor.database.connectiontest:1568713863992:74:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor.test.connection</TenantID>
<AccountingEntityID/>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Replace"/>
</ActionCriteria>
</Sync>
<employee>
<empnum>1003</empnum>
<fullname>Tim Bone </fullname>
<dateofhire>2014-01-01</dateofhire>
<lastdaterecord>2019-09-17T11:28:20.287</lastdaterecord>
</employee>
</DataArea>
</Syncemployee>
infor.database.connectiontest
外部的
一个错误
2019-09-17T09:51:03.996Z
信息数据库连接测试:1568713863992:74:0
信息测试连接
infor.database.connectiontest
外部的
一个错误
2019-09-17T09:51:03.996Z
信息数据库连接测试:1568713863992:74:0
信息测试连接
1001
无名氏
2009-08-28
2019-09-17T11:28:20.287
infor.database.connectiontest
外部的
一个错误
2019-09-17T09:51:03.996Z
信息数据库连接测试:1568713863992:74:0
信息测试连接
1002
无名氏
2009-08-28
2019-09-17T11:28:20.287
infor.database.connectiontest
外部的
一个错误
2019-09-17T09:51:03.996Z
信息数据库连接测试:1568713863992:74:0
信息测试连接
1003
蒂姆·博恩
2014-01-01
2019-09-17T11:28:20.287
如果在一个结果中多次重复“原始文件的相同结构”,那么您就不再拥有格式良好的文档,因为您有多个根元素,尽管在XSLT转换结果中这是可能的,但这是一个不寻常的结果。如果您真的想要这样的结果,那么在另一个线程的方法中,您需要做的就是显式地开始处理
<xsl:template match="/">
<xsl:apply-templates select="//employee"/>
</xsl:template>
那么,你到底在哪里处理这个问题?如果您的处理器支持XSLT2.0,请使用
xsl:result文档
说明:您好,Michael,我有点结巴,因为我不知道如何使用xsl:result文档。你介意帮我举个例子吗?@Martin Honnen,你这里的代码对我的案例不起作用,因为它还捕获了Syncemployee标记,除了雇员重复标记之外,我怎么能跳过Syncemployee标记tag@zanza67,您是否将另一个问题中的代码改编为XML?显然,没有任何通用代码可以神奇地处理任何XML,但问题是相同的,因此将任何xsl:template match=“FlightGroup”
更改为xsl:template match=“employee”
,并将xsl:result document href=“{/Info/Campaign/CampaignNumber}-{FlightGroup id}.XML”
到一些对您的数据有意义的东西,比如xsl:result document href=“employee-{empnum}.xml”
并且您应该得到结果文档employee-1001.xml
等等。我添加了一个更通用的,现有答案的参数化XSLT 3版本,这将简化将代码应用于具有相同问题的任何人的任务,但适用于不同的XML结构和用于拆分的不同目标元素。