2016-09-23 7 views
0

このファイルの子にcredit_union_nameの属性値を追加する必要があります。ファイルの下のcredit_union_idで上記ファイルのcredit_union_idを照合し、下の子のname属性の値を返すことによってxmlファイルの属性値を第2のxmlファイルの属性値に従って追加する

<branches> 
<branch branch_id="1" credit_union_id="1" branch_name="Sample Branch" phone_no="555-555-5555" fax_no="555-555-5555" toll_no="555-555-5555"> 
<address> 
<suitenumber/> 
<streetnumber>5030</streetnumber> 
<streetsuffix/> 
<streetname>51</streetname> 
<streettype>ST</streettype> 
<streetdirection/> 
<city>CITY NAME</city> 
<province>ON</province> 
<postalcode>0P0 P0P</postalcode> 
<longitude>0.0</longitude> 
<latitude>0.0</latitude> 
</address> 
<hours> 
<monopen>9:30</monopen> 
<monclose>17:00</monclose> 
<tueopen>9:30</tueopen> 
<tueclose>17:00</tueclose> 
<wedopen>9:30</wedopen> 
<wedclose>17:00</wedclose> 
<thursopen>9:30</thursopen> 
<thursclose>17:00</thursclose> 
<friopen>9:30</friopen> 
<friclose>17:00</friclose> 
<satopen>Closed</satopen> 
<satclose>Closed</satclose> 
<sunopen>Closed</sunopen> 
<sunclose>Closed</sunclose> 
</hours> 
</branch> 
</branches> 

<organizations> 
<organization credit_union_id="1" name="Credit Union Sample" operatingas="Sample"> 
<licenseserviceaquirer> 
<Acculink>True</Acculink> 
<Interac>True</Interac> 
<TheExchange>False</TheExchange> 
<Plus>False</Plus> 
<Cirrus>True</Cirrus> 
<Maestro>True</Maestro> 
<VisaCredit>False</VisaCredit> 
<VisaDebit>False</VisaDebit> 
<MasterCardCredit>False</MasterCardCredit> 
<MasterCardDebit>True</MasterCardDebit> 
</licenseserviceaquirer> 
<services> 
<CardServices>True</CardServices> 
<CommercialLoans>True</CommercialLoans> 
<ConsumerLoans>True</ConsumerLoans> 
<DepositServices>True</DepositServices> 
<AcculinkInBranch>True</AcculinkInBranch> 
<InsuranceServices>True</InsuranceServices> 
<InvestmentServices>False</InvestmentServices> 
<LeasingServices>False</LeasingServices> 
<MerchantServices>False</MerchantServices> 
<PayrollDeduction>False</PayrollDeduction> 
<RemoteBanking>True</RemoteBanking> 
<VirtualBanking>True</VirtualBanking> 
<ETransfer>True</ETransfer> 
<CrossBorderDebit>False</CrossBorderDebit> 
<InteracOnlinePayment>False</InteracOnlinePayment> 
<AutomatedHotCardServices>True</AutomatedHotCardServices> 
<DingFree>True</DingFree> 
<Contactless>False</Contactless> 
</services> 
</organization> 
</organizations> 

これをXSLTスタイルシートで実行しようとしています。

私の記事を読んで/助けてくれてありがとう!

+0

お使いのプロセッサはXSLT 2.0をサポートしていますか? –

+0

はい、あります。 !!!!!!!!!!!!!! –

答えて

0

XSLT 2.0では、別のドキュメントへの相互参照を解決するのに、keysを簡単に使用できます。ここでは、最小化の例です:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:param name="path-to-organizations">organizations.xml</xsl:param> 

<xsl:key name="org" match="organization" use="@credit_union_id" /> 

<xsl:template match="/branches"> 
    <xsl:copy> 
     <xsl:for-each select="branch"> 
      <xsl:copy> 
       <name> 
        <xsl:value-of select="@branch_name"/> 
       </name> 
       <organization> 
        <xsl:value-of select="key('org', @credit_union_id, document($path-to-organizations))/@name"/> 
       </organization> 
      </xsl:copy> 
     </xsl:for-each> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

このスタイルシートは、第二のファイルを指すパラメータで、あなたの最初のファイルに適用されると、結果は次のようになります。

<?xml version="1.0" encoding="UTF-8"?> 
<branches> 
    <branch> 
     <name>Sample Branch</name> 
     <organization>Credit Union Sample</organization> 
    </branch> 
</branches> 
+0

'$ path-to-organizations'パラメータで2番目のファイルへの正しいパスを指定してください。私の例では 'organizations.xml'を使用しましたが、ファイルの実際の名前やその場所を知らないのです。 –

関連する問題