【发布时间】:2014-03-17 18:50:53
【问题描述】:
我希望您能在这个问题上为我指明正确的方向。我正在尝试获取组织结构图的过滤结果以显示每个部门。下面是源 xml 的示例。如果有更好的方法可以根据我的要求进行重组,我可以重组 xml 源。
源 XML:
<OrgTree>
<employee ID="1">
<Name>John</Name>
<Department>President's Office</Department>
<employee ID="2">
<Name>Ron</Name>
<Department>President's Office</Department>
<employee ID="3">
<Name>Don</Name>
<Department>CEO</Department>
</employee>
</employee>
<employee ID="4">
<Name>Mike</Name>
<Department>Finance</Department>
<employee ID="5">
<Name>Mark</Name>
<Department>Accounting</Department>
<employee ID="6">
<Name>Marni</Name>
<Department>Accounting</Department>
</employee>
</employee>
<employee ID="7">
<Name>Mindy</Name>
<Department>Investments</Department>
</employee>
</employee>
</employee>
</OrgTree>
我想获得两种不同形式的输出。
- 按部门过滤并获取该部门和子部门的所有节点(按财务树过滤)。
输出 1:
<OrgTree>
<employee ID="4">
<Name>Mike</Name>
<Department>Finance</Department>
<employee ID="5">
<Name>Mark</Name>
<Department>Accounting</Department>
<employee ID="6">
<Name>Marni</Name>
<Department>Accounting</Department>
</employee>
</employee>
<employee ID="7">
<Name>Mindy</Name>
<Department>Investments</Department>
</employee>
</employee>
</OrgTree>
- 按特定部门过滤输出并仅获取该部门中的节点
输出 2:
<OrgTree>
<employee ID="5">
<Name>Mark</Name>
<Department>Accounting</Department>
<employee ID="6">
<Name>Marni</Name>
<Department>Accounting</Department>
</employee>
</employee>
</OrgTree>
我发现了几篇关于像 XSLT Filter result using XSLT array 这样的过滤的帖子,但是我的 xml 结构非常不同,以至于我没有运气让这种方法发挥作用。
我在 SharePoint 中,所以我正在尝试按部门过滤的 xsl 在下面,但我没有得到任何结果,因为 xml 中只有一个父行。我已经使用了许多不同的方法在 rowview 模板中进行过滤,但我只想将过滤后的结果传递给 rowview 模板,而不必遍历那里的所有节点。考虑到子节点的不同深度,我不知道如何做到这一点。
<xsl:for-each select="$Rows[Department = 'CFO']">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
任何帮助,指导将不胜感激。
【问题讨论】:
-
您几乎没有包含任何代码。或许可以尝试多写一些。
-
感谢版权噩梦的反馈。我本可以粘贴 for each 的 20 种变体,然后选择我尝试过的语句。但它们并没有按照我需要的方式工作。正如我所说,我不知道如何遍历未知深度的节点。而我在 dvt_1.rowview 中为每个员工绘制组织结构图的代码与手头的问题无关。
-
如果代码那么敏感,也许这是一个你不能在公共论坛上问的问题。试着把问题分解成更小的部分,然后你可以从那里找出解决方案。
标签: xml xslt filter organizational-chart