2016-10-24 14 views
0

私は3つのxml構造を持っています。欠落している場合は要素を作成するか、要素が既に存在する場合はそれを選択して、要素を作成して均質化する必要があります。xsltで欠落しているxml要素を作成するにはどうすればよいですか?

Aは私が必要とする要素のほとんどを持っている構造:構造Bは、要素imprint内部publisher不足しているのに対し

<biblStruct> 
      <analytic> 
       <title type="label">Gronemann/Maaß/Peters/Schrader 2001</title> 
       <title type="titel">Körper und Schrift. Beiträge zum 16. Nachwuchskolloquium der 
       Romanistik, Leipzig, 14.-17. Juni 2000</title> 
       <idno>6677</idno> 
       <idno>6677</idno> 
       <author> 
       <persName>Gronemann, Claudia;Maaß, Christiane;Peters, Sabine A.;Schrader, 
        Sabine</persName> 
       </author> 
      </analytic> 
      <monogr> 
       <title type="label">Gronemann/Maaß/Peters/Schrader 2001</title> 
       <title type="titel">Körper und Schrift. Beiträge zum 16. Nachwuchskolloquium der 
       Romanistik, Leipzig, 14.-17. Juni 2000</title> 
       <idno type="standortsign">UB Bern;SUB Göttingen</idno> 
       <author> 
       <persName>Gronemann, Claudia;Maaß, Christiane;Peters, Sabine A.;Schrader, 
        Sabine</persName> 
       </author> 
       <imprint> 
       <publisher>Romanistischer Verlag</publisher> 
       <pubPlace> 
        <placeName>Bonn</placeName> 
       </pubPlace> 
       <date>2001</date> 
       </imprint> 
      </monogr> 
      <relatedItem type="enhalt"> 
       <ref>Objekt 3257/Biographien-Werke</ref> 
      </relatedItem> 
      <note type="faustdb">biogra</note> 
      <note type="objektart">Bibliographie</note> 
      <note type="objektart">Bibliographie</note> 
      <note type="erstellt"> 
       <date>2016-09-18T00:00:00.000</date> 
      </note> 
      <note type="letztebearb"> 
       <date>2016-09-18T00:00:00.000</date> 
      </note> 
     </biblStruct> 

<biblStruct> 
      <analytic> 
       <title type="label">Volmer 2001</title> 
       <title type="titel">Die Gebrechen des Lebens. Zur Körpererfahrung in 
       Korrespondenzen des 18. Jahrhunderts</title> 
       <idno>3257</idno> 
       <idno>3257</idno> 
       <author> 
       <persName>Volmer, Annett</persName> 
       </author> 
      </analytic> 
      <monogr> 
       <title type="label">Volmer 2001</title> 
       <title type="titel">Die Gebrechen des Lebens. Zur Körpererfahrung in 
       Korrespondenzen des 18. Jahrhunderts</title> 
       <idno type="standortsign">UB Basel: AP IX 5844</idno> 
       <author> 
       <persName>Volmer, Annett</persName> 
       </author> 
       <imprint> 
       <biblScope unit="sammelwerkin">Objekt 6677/Biographien-Werke</biblScope> 
       <biblScope unit="sammelwerkseiten">138-149</biblScope> 
       </imprint> 
      </monogr> 
      <note type="faustdb">biogra</note> 
      <note type="objektart">Bibliographie</note> 
      <note type="objektart">Bibliographie</note> 
      <note type="erstellt"> 
       <date>2005-01-19T00:00:00.000</date> 
      </note> 
      <note type="letztebearb"> 
       <date>2016-10-10T00:00:00.000</date> 
      </note> 
      <note type="kategorie">Briefkultur, Netzwerke, 
       Transfer;Wissen(schaft)sgeschichte/Medizin</note> 
     </biblStruct> 

を、私はこのpublisher要素を作成できるようにしたいと思いますそれが欠落している場合imprintの中にネストされています - 私は非常に多様なエントリを含む巨大なリストを扱っています。

<monogr> 
       <imprint> 
       <publisher></publisher> 
       </imprint> 
      </monogr> 

ので、出力がすべき:私は次の要素analytic後に追加したいと思います。この場合、

<biblStruct> 
      <analytic> 
       <idno>24587</idno> 
       <idno>24587</idno> 
       <author> 
       <persName>Person aus Ref-Tabelle</persName> 
       </author> 
      </analytic> 
      <note type="faustdb">Publik</note> 
      <note type="objektart">Rezensionen</note> 
      <note type="objektart">Rezensionen</note> 
     </biblStruct> 

同じでも、より多くの要素を欠いているCを、構造に適用されますbe:

<biblStruct> 
      <analytic> 
       <idno>24587</idno> 
       <idno>24587</idno> 
       <author> 
       <persName>Person aus Ref-Tabelle</persName> 
       </author> 
      </analytic> 
      <monogr> 
       <imprint> 
       <publisher></publisher> 
       </imprint> 
      </monogr> 
      <note type="faustdb">Publik</note> 
      <note type="objektart">Rezensionen</note> 
      <note type="objektart">Rezensionen</note> 
     </biblStruct> 

要素が空であるかどうかは関係ありません彼は瞬間。どのように私はこれを達成することができますか?

これらのXMLエントリはすべて同じファイルにあり、まだソートできないことを覚えておいてください。すでに存在するか、まだ存在しない場合は、必要な要素を考慮して作成する必要があります。ありがとう!

+1

データは利用できません。存在しない要素についてXPathを使用してドキュメントをクエリするのはエラーではなく、単に空のリストを返すだけではありません。空の要素を作成するのは、「その理由」がその原則に反するからです。これは問題ないですが、問題は本当に必要ですか?何のために? – Tomalak

+0

ご意見ありがとうございます。私はそれらを作成したいと思うので、私は将来的に値で要素を埋めることを望んでいる。現時点では空になることができますが、私は検証のためにそれらを必要とします。 –

+1

"*存在するかどうかを考慮して、必要な要素を作成する必要があります。*または、存在するかどうかにかかわらず、すべてを単純に作成することもできます。対応する値。テンプレートがテンプレートと呼ばれる理由があります。 –

答えて

0

ご意見ありがとうございます。私はこれを試してみましたが、それが最初のケースのために働い:XMLの周りの基本的な設計原理の一つは、要素が悪影響なしに行方不明と要素が存在しない場合は、その関連することを示すことにすることができるということである

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs tei" version="2.0" 
xmlns:tei="http://www.tei-c.org/ns/1.0"> 

<xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="tei:imprint[not(./tei:publisher)]"> 
    <xsl:copy> 
     <xsl:element name="tei:publisher"> </xsl:element> 
    </xsl:copy> 

</xsl:template> 

+0

ちょうど、 'と言う必要はありません。単に ''と直接言ってください。はるかに短く、読みやすくなりました。 – Tomalak

+0

また、 'tei:imprint'の通常のテンプレートの中では、おそらく' ... 'を使用します。そうすれば特別なケースは少なくなるでしょうし、子供たちの順序を完全にコントロールすることができます。 – Tomalak

+0

私はこれがあなたがしたいことはしないと思っています。「インプリント」内に存在する他の要素をコピーしてはいけませんか?とにかく、この方法を続けると、あなたのスタイルシートはまもなく管理不能な例外の森に成長するだろうと思う。 –

関連する問題