我有類似這樣的XML文件(除去更多的節點和細節):過濾XML節點
<?xml version="1.0" encoding="utf-8"?>
<Message xmlns="http://www.theia.org.uk/ILR/2011-12/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<CollectionDetails>
<Collection>ILR</Collection>
<Year>1112</Year>
<FilePreparationDate>2011-10-06</FilePreparationDate>
</CollectionDetails>
<Source>
<ProtectiveMarking>PROTECT-PRIVATE</ProtectiveMarking>
</Source>
</Header>
<SourceFiles>
<SourceFile>
<SourceFileName>A10004705001112004401.ER</SourceFileName>
<FilePreparationDate>2011-10-05</FilePreparationDate>
</SourceFile>
</SourceFiles>
<LearningProvider>
<UKPRN>10004705</UKPRN>
<UPIN>107949</UPIN>
</LearningProvider>
<Learner>
<ULN>4682272097</ULN>
<GivenNames>Peter</GivenNames>
<LearningDelivery>
<LearnAimRef>60000776</LearnAimRef>
</LearningDelivery>
<LearningDelivery>
<LearnAimRef>ZPROG001</LearnAimRef>
</LearningDelivery>
</Learner>
<Learner>
<ULN>3072094321</ULN>
<GivenNames>Thomas</GivenNames>
<LearningDelivery>
<LearnAimRef>10055320</LearnAimRef>
</LearningDelivery>
<LearningDelivery>
<LearnAimRef>10002856</LearnAimRef>
</LearningDelivery>
<LearningDelivery>
<LearnAimRef>1000287X</LearnAimRef>
</LearningDelivery>
</Learner>
</Message>
我需要過濾此,使得有孩子的LearningDelivery LearnAimRef只有學習者記錄ZPROG001將顯示所以在這種情況下,輸出將是第一個學生,但不是第二:
<?xml version="1.0" encoding="utf-8"?>
<Message xmlns="http://www.theia.org.uk/ILR/2011-12/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<CollectionDetails>
<Collection>ILR</Collection>
<Year>1112</Year>
<FilePreparationDate>2011-10-06</FilePreparationDate>
</CollectionDetails>
<Source>
<ProtectiveMarking>PROTECT-PRIVATE</ProtectiveMarking>
</Source>
</Header>
<SourceFiles>
<SourceFile>
<SourceFileName>A10004705001112004401.ER</SourceFileName>
<FilePreparationDate>2011-10-05</FilePreparationDate>
</SourceFile>
</SourceFiles>
<LearningProvider>
<UKPRN>10004705</UKPRN>
<UPIN>107949</UPIN>
</LearningProvider>
<Learner>
<ULN>4682272097</ULN>
<GivenNames>Peter</GivenNames>
<LearningDelivery>
<LearnAimRef>60000776</LearnAimRef>
</LearningDelivery>
<LearningDelivery>
<LearnAimRef>ZPROG001</LearnAimRef>
</LearningDelivery>
</Learner>
</Message>
我已經調查如何做到這一點,並認爲正確的方式做,這是使用XSL轉換過程xml和根據需要輸出到一個新文件(在c#中執行此操作)。經過幾個小時試圖圍繞XSLT語法包裝我的頭,我仍然卡住,無法獲得我想要的輸出。任何幫助非常感謝。
+1爲一個很好的答案。 –
優秀的答案,這正是我想要的。我希望我能更多地理解XSLT,但它對我來說只是一次。 – PeteT