2011-06-27 16 views
0

2つのXML文書を結合するのが面倒です。既存のフィールドを見つけたときに上書きする新しい第2のxmlが必要です。見つかったときに2つのXML文書をマージしてXMLフィールドを上書きする

<filemeta filetype="Video"> 
    <heading>News Headlines</heading> 
    <shortblurb>The latest news roundup</shortblurb> 
    <description /> 
    <files> 
     <file type="coverimage">headlines.png</file> 
    </files> 
    <Comments /> 
    <AlbumTitle /> 
    <TrackNumber /> 
    <ArtistName /> 
    <Year /> 
    <Genre /> 
    <TrackTitle /> 
    <duration>00:02:22</duration> 
    <totalbitrate>1168 kb/s</totalbitrate> 
    <videocodec>h264</videocodec> 
    <pixelformat>yuv420p</pixelformat> 
    <resolution>640x360</resolution> 
    <audiocodec>aac</audiocodec> 
    <audiofrequency>44100 Hz</audiofrequency> 
    <channelmulplicity>stereo</channelmulplicity> 
    <audioformat>s16</audioformat> 
    <audiobitrate>111 kb/s</audiobitrate> 
</filemeta> 

これとマージします。

<filemeta type="Video"> 
    <duration>00:00:45</duration> 
    <totalbitrate>548 kb/s</totalbitrate> 
    <videocodec>h264</videocodec> 
    <pixelformat>yuv420p</pixelformat> 
    <resolution>720x576</resolution> 
    <audiocodec>aac</audiocodec> 
    <audiofrequency>48000 Hz</audiofrequency> 
    <channelmulplicity>stereo</channelmulplicity> 
    <audioformat>s16</audioformat> 
    <audiobitrate>65 kb/s</audiobitrate> 
</filemeta> 

私は、彼らが唯一のため、私のXMLを無効に、最初の1の終わりに2番目のスクリプトを追加しているように見えるが、様々なXSLT scriptsthisで作業しようとしました。理想的には私はこのC#

助けていただきありがとうございます!

+0

XSLTバージョンでお願いします。 –

答えて

0

このquestionをご覧ください。私はあなたの問題を解決すると思います。

+0

私はトップコードを試しましたが、ArgumentNullExceptionエラーが発生しました。 'column'引数はnullにはなりません。 – wonea

+0

@wonea - 私の答えを更新しました。 – Bibhu

0

これは、アイデアを出すために可能な()XSLT 1.0ソリューションです。

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

    <xsl:variable name="data2" select="document('test_i2.xml')/filemeta"/> 

    <xsl:template match="filemeta"> 
     <xsl:copy> 
     <xsl:for-each select="*"> 
      <xsl:variable name="element1" select="name(.)"/> 
      <xsl:choose> 
       <xsl:when test="count($data2/*[name()=$element1])!=0"> 
        <xsl:copy-of select="$data2/*[name()=$element1]"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:copy-of select="."/> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:for-each> 
    </xsl:copy>  
    </xsl:template> 

</xsl:stylesheet> 
関連する問題