2016-04-06 12 views
0

ネット全体を検索しましたが、私のXML変換の問題に対する解決策は見つかりませんでした。私はこのようなXMLがあります:最初のステップとしてXSLT:1つの要素(子供を含む)を他のノードにコピーする

<?xml version="1.0" encoding="UTF-8"?> 
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2016-04-06T10:00:04"> 
    <studyroot> 
     <crocode>AMS</crocode> 
     <croname>AMS GmbH</croname> 
     <exportdatetime>2016-04-04T10:17:59</exportdatetime> 
     <studynumer>STUDYXYZ</studynumer> 
     <site> 
      <number>005</number> 
      <name>Dr. ABC</name> 
      <paymentplan>Laboruntersuchung</paymentplan> 
      <studycode>STUDYXYZ</studycode> 
     </site> 
     <site> 
      <number>016</number> 
      <name>Dr. XYZ</name> 
      <paymentplan>Laboruntersuchung</paymentplan> 
      <studycode>STUDYXYZ</studycode> 
     </site> 
     <site> 
      <number>053</number> 
      <name>Dr. DEF</name> 
      <patient>01</patient> 
      <paymentplan>Laboruntersuchung</paymentplan> 
      <studycode>STUDYXYZ</studycode> 
     </site> 
    </studyroot> 
    <patient> 
     <site>053</site> 
     <number>01</number> 
     <service>Hauptuntersuchung</service> 
    </patient> 
    <service> 
     <site>053</site> 
     <pat>01</pat> 
     <code>HAU</code> 
     <iteration>1</iteration> 
     <name>Hauptuntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
    <service> 
     <site>053</site> 
     <code>PAR</code> 
     <iteration>1</iteration> 
     <name>Laboruntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
    <paymentplan> 
     <code>LAB</code> 
     <name>Laboruntersuchung</name> 
     <service>PAR</service> 
    </paymentplan> 
    <service> 
     <site>053</site> 
     <pat>01</pat> 
     <code>HAU</code> 
     <iteration>1</iteration> 
     <name>Hauptuntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
    <service> 
     <site>053</site> 
     <code>PAR</code> 
     <iteration>1</iteration> 
     <name>Laboruntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
</dataroot> 

を、私はpaymentplanフィット内部の名札場合、親datarootpaymentplanタグですべてのサイトのタグにpaymentplanタグを代用します。それは私が立ち往生している場所です。誰かが私を助けることができる、私はXSLTに非常に新しいですか?ありがとうございます。

+0

あなたは、この場合に予想される出力を表示することができますか?ありがとうございました! –

答えて

0

copy-of現在のpaymentplan要素またはcopy-of適切な/dataroot/paymentplan要素のいずれかです。これは次の出力を与えるソースファイルにHauptuntersuchungで二Laboruntersuchungを交換するための

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method="xml"/> 

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

<xsl:template match="paymentplan[local-name(..) = 'site']"> 
    <xsl:variable name="curUntersuchung" select="text()" /> 
    <xsl:choose> 
    <xsl:when test="/dataroot/paymentplan[name/text() = $curUntersuchung]"> 
     <xsl:copy-of select="/dataroot/paymentplan[name/text() = $curUntersuchung]" /> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:copy-of select="." /> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

</xsl:stylesheet> 

:あなたはあなたの期待出力を掲示していないとして、私は、あなたが望むものを伝えるためにのために

<?xml version="1.0"?> 
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2016-04-06T10:00:04"> 
    <studyroot> 
     <crocode>AMS</crocode> 
     <croname>AMS GmbH</croname> 
     <exportdatetime>2016-04-04T10:17:59</exportdatetime> 
     <studynumer>STUDYXYZ</studynumer> 
     <site> 
      <number>005</number> 
      <name>Dr. ABC</name> 
      <paymentplan> 
       <code>LAB</code> 
       <name>Laboruntersuchung</name> 
       <service>PAR</service> 
      </paymentplan> 
      <studycode>STUDYXYZ</studycode> 
     </site> 
     <site> 
      <number>016</number> 
      <name>Dr. XYZ</name> 
      <paymentplan>Hauptuntersuchung</paymentplan> 
      <studycode>STUDYXYZ</studycode> 
     </site> 
     <site> 
      <number>053</number> 
      <name>Dr. DEF</name> 
      <patient>01</patient> 
      <paymentplan> 
       <code>LAB</code> 
       <name>Laboruntersuchung</name> 
       <service>PAR</service> 
      </paymentplan> 
      <studycode>STUDYXYZ</studycode> 
     </site> 
    </studyroot> 
    <patient> 
     <site>053</site> 
     <number>01</number> 
     <service>Hauptuntersuchung</service> 
    </patient> 
    <service> 
     <site>053</site> 
     <pat>01</pat> 
     <code>HAU</code> 
     <iteration>1</iteration> 
     <name>Hauptuntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
    <service> 
     <site>053</site> 
     <code>PAR</code> 
     <iteration>1</iteration> 
     <name>Laboruntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
    <paymentplan> 
     <code>LAB</code> 
     <name>Laboruntersuchung</name> 
     <service>PAR</service> 
    </paymentplan> 
    <service> 
     <site>053</site> 
     <pat>01</pat> 
     <code>HAU</code> 
     <iteration>1</iteration> 
     <name>Hauptuntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
    <service> 
     <site>053</site> 
     <code>PAR</code> 
     <iteration>1</iteration> 
     <name>Laboruntersuchung</name> 
     <done>0</done> 
     <obsolete>0</obsolete> 
     <completedate>2016-04-04T00:00:00</completedate> 
    </service> 
</dataroot> 
0

それは難しいですXML。しかし、あなたの質問から、私はあなたが

<site> 
    <number>005</number> 
    <name>Dr. ABC</name> 
    <paymentplan> 
     <code>LAB</code> 
     <name>Laboruntersuchung</name> 
     <service>PAR</service> 
    </paymentplan> 
    <studycode>STUDYXYZ</studycode> 
</site> 

<site> 
    <number>005</number> 
    <name>Dr. ABC</name> 
    <paymentplan>Laboruntersuchung</paymentplan> 
    <studycode>STUDYXYZ</studycode> 
</site> 

を変換したいと仮定すると、その正しいですか?

もしそうなら、あなたのXSLテンプレートは次のようになります。

<xsl:template match="//site/paymentplan"> 
    <xsl:apply-templates select="ancestor::dataroot/paymentplan[name=current()]"/> 
</xsl:template> 
+0

それは働いています:-)あなたにとても感謝します! –

+0

Gern geschehen! ;-) –

関連する問題