【发布时间】:2021-08-01 11:43:00
【问题描述】:
我想使用 xslt 更改跳过元素的子元素的 ParentId。我的输入文件:
<?xml version="1.0" encoding="UTF-8"?>
<Hierarchy>
<Board>
<Name>President</Name>
<Id>ABCDE</Id>
<ParentId></ParentId>
<General>
<Name>President</Name>
<Description>Top level of the Hierarchy</Description>
<Template>LEVEL1</Template>
</General>
</Board>
<Board>
<Name>VP</Name>
<Id>EFGHI</Id>
<ParentId>ABCDE</ParentId>
<General>
<Name>VP</Name>
<Description>Below the President</Description>
<Template>LEVEL2</Template>
</General>
</Board>
<Board>
<Name>Department_Heads</Name>
<Id>JKLMN</Id>
<ParentId>EFGHI</ParentId>
<General>
<Name>Department_Heads</Name>
<Description>Reports to the VP</Description>
<Template>LEVEL3</Template>
</General>
</Board>
<Board>
<Name>Supervisors</Name>
<Id>OPQRS</Id>
<ParentId>JKLMN</ParentId>
<General>
<Name>Supervisors</Name>
<Description>Reports to the Reports to Dep Heads</Description>
<Template>LEVEL4</Template>
</General>
</Board>
<Board>
<Name>Employees</Name>
<Id>TUVWX</Id>
<ParentId>OPQRS</ParentId>
<General>
<Name>Employees</Name>
<Description>Reports to the Reports to Dep Heads</Description>
<Template>LEVEL5</Template>
</General>
</Board>
</Hierarchy>
预期的输出文件:
<?xml version="1.0" encoding="UTF-8"?>
<Hierarchy>
<Board>
<Name>President</Name>
<Description>Top level of the Hierarchy</Description>
<Template>LEVEL1</Template>
<Id>ABCDE</Id>
<ParentId></ParentId>
<Board>
<Name>VP</Name>
<Description>Below the President</Description>
<Template>LEVEL2</Template>
<Id>EFGHI</Id>
<ParentId>ABCDE</ParentId>
<Board>
<Name>Supervisors</Name>
<Description>Reports to the Reports to Dep Heads</Description>
<Template>LEVEL4</Template>
<Id>OPQRS</Id>
<ParentId>EFGHI</ParentId>
<Board>
<Name>Employees</Name>
<Description>Reports to the Reports to Dep Heads</Description>
<Template>LEVEL5</Template>
<Id>TUVWX</Id>
<ParentId>OPQRS</ParentId>
</Board>
</Board>
</Board>
</Board>
</Hierarchy>
现在在我提出的另一个问题的帮助下,我能够找到一种跳过元素的方法。问题链接如下: Is it possible to skip a level in a Hierarchy using XSLT?
但是,如果您在预期的输出中观察到,主管的 ParentId 更改为 VP 的 Id,因此完全跳过了元素“Depeartment Heads”。这可能吗?有人可以为此提供可能的解决方案吗?提前致谢。
【问题讨论】: