我将如何提取以下 XMLSectionLabels
中每个的唯一性:FormDef
<XML>
<FormDef OID="F_TEST_1" Name="Test Form 1">
<ItemGroupRef ItemGroupOID="TEST_GROUP_1" />
<ItemGroupRef ItemGroupOID="TEST_GROUP_4" />
</FormDef>
<FormDef OID="F_TEST_2" Name="Test Form 2">
<ItemGroupRef ItemGroupOID="TEST_GROUP_2" />
</FormDef>
<FormDef OID="F_TEST_3" Name="Test Form 3">
<ItemGroupRef ItemGroupOID="TEST_GROUP_2"/>
<ItemGroupRef ItemGroupOID="TEST_GROUP_3"/>
</FormDef>
<FormDef OID="F_TEST_4" Name="Test Form 4">
<ItemGroupRef ItemGroupOID="TEST_GROUP_4"/>
</FormDef>
<ItemGroupDef OID="TEST_GROUP_1" Name="Ungrouped">
<ItemRef ItemOID="I_MSA1_INIT" />
<ItemRef ItemOID="I_MSA1_FORMD" />
<ItemRef ItemOID="I_MSA1_MSA1_CONS" />
<ItemRef ItemOID="I_MSA1_MSA1_PGT" />
</ItemGroupDef>
<ItemGroupDef OID="TEST_GROUP_2" Name="MSA1_complyreasG" >
<ItemRef ItemOID="I_MSA1_MSA1_NOELIGREAS" />
<ItemRef ItemOID="I_MSA1_MSA1_COMPLYREAS" />
</ItemGroupDef>
<ItemGroupDef OID="TEST_GROUP_3" Name="Ungrouped">
<ItemRef ItemOID="I_MSA2_INIT" />
<ItemRef ItemOID="I_MSA2_FROMD" />
<ItemRef ItemOID="I_MSA2_IDV" />
<ItemRef ItemOID="I_MSA2_MSA2_INITBF" />
</ItemGroupDef>
<ItemGroupDef OID="TEST_GROUP_4" Name="MSA2_POARTprecG">
<ItemRef ItemOID="I_MSA2_MSA2_POARTPREC" />
<ItemRef ItemOID="I_MSA2_MSA2_POARTNBV" />
<ItemRef ItemOID="I_MSA2_MSA2_LOARTPREC" />
</ItemGroupDef>
<ItemDef OID="I_MSA1_INIT">
<ItemDetails ItemOID="I_MSA1_INIT">
<ItemPresentInForm FormOID="F_TEST_1">
<SectionLabel>Section1</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA1_FORMD">
<ItemDetails ItemOID="I_MSA1_FORMD">
<ItemPresentInForm FormOID="F_TEST_1">
<SectionLabel>Section2</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA1_MSA1_CONS">
<ItemDetails ItemOID="I_MSA1_MSA1_CONS">
<ItemPresentInForm FormOID="F_TEST_1">
<SectionLabel>Section3</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA1_MSA1_NOELIGREAS">
<ItemDetails ItemOID="I_MSA1_MSA1_NOELIGREAS">
<ItemPresentInForm FormOID="F_TEST_2">
<SectionLabel>Section1</SectionLabel>
</ItemPresentInForm>
<ItemPresentInForm FormOID="F_TEST_3">
<SectionLabel>Section1</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA1_MSA1_COMPLYREAS">
<ItemDetails ItemOID="I_MSA1_MSA1_COMPLYREAS">
<ItemPresentInForm FormOID="F_TEST_2">
<SectionLabel>Section2</SectionLabel>
</ItemPresentInForm>
<ItemPresentInForm FormOID="F_TEST_3">
<SectionLabel>Section2</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA2_INIT">
<ItemDetails ItemOID="I_MSA2_INIT">
<ItemPresentInForm FormOID="F_TEST_3">
<SectionLabel>Section1</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA2_FROMD">
<ItemDetails ItemOID="I_MSA2_FROMD">
<ItemPresentInForm FormOID="F_TEST_3">
<SectionLabel>Section2</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA2_IDV">
<ItemDetails ItemOID="I_MSA2_IDV">
<ItemPresentInForm FormOID="F_TEST_3">
<SectionLabel>Section3</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA2_MSA2_POARTPREC">
<ItemDetails ItemOID="I_MSA2_MSA2_POARTPREC">
<ItemPresentInForm FormOID="F_TEST_1">
<SectionLabel>Section1</SectionLabel>
</ItemPresentInForm>
<ItemPresentInForm FormOID="F_TEST_4">
<SectionLabel>Section1</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA2_MSA2_POARTNBV">
<ItemDetails ItemOID="I_MSA2_MSA2_POARTNBV">
<ItemPresentInForm FormOID="F_TEST_1">
<SectionLabel>Section2</SectionLabel>
</ItemPresentInForm>
<ItemPresentInForm FormOID="F_TEST_4">
<SectionLabel>Section2</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
<ItemDef OID="I_MSA2_MSA2_LOARTPREC">
<ItemDetails ItemOID="I_MSA2_MSA2_LOARTPREC">
<ItemPresentInForm FormOID="F_TEST_1">
<SectionLabel>Section3</SectionLabel>
</ItemPresentInForm>
<ItemPresentInForm FormOID="F_TEST_4">
<SectionLabel>Section3</SectionLabel>
</ItemPresentInForm>
</ItemDetails>
</ItemDef>
</XML>
首先我定义一个键:
<xsl:key name="labels" match="ItemDef/ItemDetails/ItemPresentInForm" use="@FormOID" />
然后像这样在选择中使用它:
<xsl:variable name="sections"
select="//*[local-name()='ItemDef']/*[local-name()='ItemDetails']/*[local-name()='ItemPresentInForm']
[generate-id() = generate-id(key('labels', @FormOID))]">
<xsl:value-of select="./SectionLabel" />
</xsl:variable>
但这会返回:
第
1 节 第 1 节 第 1 节
第 1
节
更改键以在SectionLabel
:
<xsl:key name="labels" match="ItemDef/ItemDetails/ItemPresentInForm" use="SectionLabel" />
XSLT 进行转换:
<xsl:variable name="sections"
select="//*[local-name()='ItemDef']/*[local-name()='ItemDetails']/*[local-name()='ItemPresentInForm']
[generate-id(.) = generate-id(key('labels', SectionLabel))]">
<xsl:value-of select="./SectionLabel" />
</xsl:variable>
返回这个:
第1
节2
节
3
节4
节1
节2节3节4节1节2节3
节
4
节1
节2
节
3
节
4
节
当我遍历每个 FormDef 时,这是文档中的所有部分标签。我的目标是获得一个输出,其中仅提取当前 FormDef 的部分标签。
预期的输出应该是:
Form OID="F_TEST_1"
Labels: Section1, Section2, Section3
Form OID="F_TEST_2"
Labels: Section1, Section2
Form OID="F_TEST_3"
Labels: Section1, Section2, Section3
Form OID="F_TEST_4"
Labels: Section1, Section2, Section3
谢谢