我有一個相當複雜的XML文件,一個更簡單,其中包含一些更復雜的文件。從複雜的 XSLT - 比較和組合兩個XML文件
一個元素:
從簡單的一<h1:Document DocKey="obj 40020528">
<h1:Block Type="obj"
CreationDate="20.03.2014 09:39:50"
CreatorID="Admin"
ChangeDate="21.01.2015 14:40:51"
ChangerID="Admin"
OwnerID="Admin"
FieldsCount="17">
<h1:Field Type="5000" Value="40020528"/>
<h1:Field Type="5060" Value="Aufnahme">
<h1:Field Type="5064" Value="unbekannt"/>
</h1:Field>
<h1:Field Type="ob28" Value="Verwalter">
<h1:Field Type="2864" Value="Köln"/>
<h1:Field Type="2900"
Value="Theaterwissenschaftliche Sammlung, Universität zu Köln"/>
<h1:Field Type="2930" Value="Fotoabteilung"/>
<h1:Field Type="2950" Value="TWS_FGL00541"/>
<h1:Field Type="907d" Value="No: 4260"/>
</h1:Field>
<h1:Field Type="ob26" Value="Aufnahmeort">
<h1:Field Type="2664" Value="unbekannt"/>
<h1:Field Type="2690" Value="Theater"/>
<h1:Field Type="2700" Value="Theater unbekannt"/>
</h1:Field>
<h1:Field Type="ob30" Value="Herstellung">
<h1:Field Type="3100" Value="unbekannt"/>
<h1:Field Type="3475" Value="Fotograf/in, Atelier"/>
</h1:Field>
<h1:Field Type="5007" Value="Darstellung">
<h1:Field Type="5009" Value="unbekannt"/>
<h1:Field Type="5010" Value="Autor/in"/>
<h1:Field Type="5013" Value="xTITELx"/>
</h1:Field>
<h1:Field Type="ob40" Value="Inszenierung">
<h1:Field Type="4100" Value="unbekannt"/>
<h1:Field Type="4475" Value="Regie"/>
</h1:Field>
<h1:Field Type="ob40" Value="Inszenierung">
<h1:Field Type="4100" Value="unbekannt"/>
<h1:Field Type="4475" Value="Bühnenbild"/>
</h1:Field>
<h1:Field Type="5200" Value="Fritz Feinhals"/>
<h1:Field Type="5220" Value="Fotografie"/>
<h1:Field Type="5230" Value="Negativ"/>
<h1:Field Type="5240" Value="Glasplattennegativ"/>
<h1:Field Type="5360" Value="18x13"/>
<h1:Field Type="55th" Value="Feinhals, Fritz"/>
</h1:Block>
</h1:Document>
一個元素:
<signatur id="TWS_FGL00541">
<datum/>
<ort/>
<ortsteil/>
<titel>Fritz Feinhals als Wotan</titel>
<fotograf/>
<komponist>Wagner, Richard</komponist>
<author/>
<regie/>
<buehnenbild/>
<darPerson/>
<freiText>Walküre</freiText>
</signatur>
我想每個「簽字:」這兩個文件的內容進行比較。如果簽名相同,則會進行更正。如果存在更正,則必須檢查來自簡單XML的哪些子元素必須放入複雜子元素的子元素中,因此必須檢查簡單XML元素的子元素是否具有值,並且如果它的價值必須放在複雜的元素中。
我不知道,最好的辦法是做什麼。我試圖像如下:
<xsl:template name="alles" match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="Halft" select="document('simpleOne.xml')" />
<xsl:variable name="Sig_Halft" select="preceding-sibling::$Halft/document/signatur" />
<xsl:variable name="Sig_HiDA" select="preceding-sibling::DocumentSet/Document/Block/Field[@Type='ob28']/Field[@Type='2950']/@Value" />
<!-- <xsl:variable name="" select="" /> -->
<xsl:template match="DocumentSet/Document">
<xsl:if test="$Sig_HiDA = $Sig_Halft"> <!-- wenn signatur gleich -->
xcbcvncvn
<!-- Datum -->
<xsl:if test="((DocumentSet/Document/Block/Field[@Type='5060']/Field[@Type='5064']/@Value != '') or (DocumentSet/Document/Block/Field[@Type='5060']/Field[@Type='5064']/@Value != $Halft/document/signatur/datum))">
</xsl:if>
<!-- Ort -->
<xsl:if test="((DocumentSet/Document/Block/Field[@Type='ob26']/Field[@Type='2664']/@Value != '') or (DocumentSet/Document/Block/Field[@Type='ob26']/Field[@Type='2664']/@Value != $Halft/document/signatur/ort))">
</xsl:if>
<!-- Ortsteil(Theater) -->
<xsl:if test="((DocumentSet/Document/Block/Field[@Type='ob26']/Field[@Type='2700']/@Value != '') or (DocumentSet/Document/Block/Field[@Type='ob26']/Field[@Type='2700']/@Value != $Halft/document/signatur/ortsteil))">
</xsl:if>
<!-- Titel -->
<xsl:if test="((DocumentSet/Document/Block/Field[@Type='5200']/@Value != '') or (DocumentSet/Document/Block/Field[@Type='5200']/@Value != $Halft/document/signatur/titel))">
<h1:Field Type="5200" Value="{$Halft/document/signatur/titel}"/>
</xsl:if>
<!-- Fotograf -->
<xsl:if test="((DocumentSet/Document/Block/Field[@Type='ob30']/Field[@Type='3100']/@Value != '') or (DocumentSet/Document/Block/Field[@Type='ob30']/Field[@Type='3100']/@Value != $Halft/document/signatur/fotograf))">
</xsl:if>
<!-- Komponist -->
<xsl:if test="((DocumentSet/Document/Block/Field[@Type='5007']/Field[@Type='5009']/@Value != '') or (DocumentSet/Document/Block/Field[@Type='5007']/Field[@Type='5009']/@Value != $Halft/document/signatur/komponist))">
</xsl:if>
</xsl:if>
</xsl:template>
不幸的是,您的示例輸入XML和示例XSL代碼顯示沒有即時關係 - 您的XSL中的任何內容都不會與XML中的任何內容匹配。請閱讀[幫助中心]中的[**如何創建最小,完整和可驗證的示例**](https://stackoverflow.com/help/mcve)文章(https://stackoverflow.com/help )並相應地修改你的帖子。 –
謝謝你的建議,但我不得不說,我不能理解他們如何不直接顯示關係。你怎麼能不假設我的xsl會匹配我的XML中的任何東西?你可以在變量和if語句中看到我擁有這兩個XML文件中元素的表達式。從我看到你的評論後的修改,我只能說,我只是沒有提到在示例XML文件,他們有複雜的父母元素「DocumentSet」和簡單的一個,其中包含對象(或元素) 如上所示。 –
回覆:不匹配:'DocumentSet/Document'不匹配任何東西,因爲1)樣本輸入XML中沒有'DocumentSet'元素,所以不會有'Document'子元素; 2)即使我們只匹配默認名稱空間中的Document,您的輸入XML在非默認名稱空間中也只有'h1:Document',並且這兩個不相同。名稱空間和前綴是XML處理的重要部分,也是棘手的。如果你使用XML很多,閱讀這些內容可能會使你受益。 –