Wie würde ich die einzigartigen SectionLabels
für jeden FormDef
in der folgenden XML extrahieren:Extract einzigartiger Text aus mehreren überlappenden Elementen
<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>
Zuerst definiere ich einen Schlüssel:
<xsl:key name="labels" match="ItemDef/ItemDetails/ItemPresentInForm" use="@FormOID" />
es dann in einem verwenden wählen Sie wie folgt:
<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>
Aber dies zurück:
Section1
Section1
Section1
Section1
den Schlüssel ändern auf der SectionLabel
aufschlagen:
<xsl:key name="labels" match="ItemDef/ItemDetails/ItemPresentInForm" use="SectionLabel" />
XSLT zur Transformation:
<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>
Returns dies:
Section1
Section2
Section3
Abschnitt4
Section1
Section2
Section3
Abschnitt4
Section1
Section2
Section3
Abschnitt4
Section1
Section2
Section3
Abschnitt4
dem alle Etiketten Abschnitt in dem Dokument ist, wenn ich über jeden FORMDEF bin Iterieren. Ich ziele darauf ab, eine Ausgabe zu erhalten, wo nur die Abschnittsbeschriftungen für das aktuelle FormDef extrahiert werden.
Das sollte erwartete Ausgabe sein:
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
Dank
Also, was sollte das Ergebnis sein? Bitte bearbeiten Sie die Frage und geben Sie das gewünschte Ergebnis an. Erklären Sie verständlicher, welche Knoten/Werte Sie auswählen möchten. –
Die Ausgabe, die Sie in Ihrer Antwort gaben, ist, was ich beabsichtigte. Es zeigt, dass Sie die Frage sehr gut verstanden haben. –
Ich habe meine * rating power * verwendet, um dies abzuleiten. Ihre Frage wäre besser definiert, wenn Sie genau die gewünschte Ausgabe produziert hätten. Es ist eine gute Idee, die Frage zu bearbeiten, und vor allem, um alle wichtigen Informationen für Ihre zukünftigen Fragen bereitzustellen. –