2016-09-23 39 views
0

我需要为此文件中的子项添加credit_union_name的属性值。根据第二个xml文件的属性值添加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> 

通过匹配下面的文件credit_union_id上述文件的credit_union_id并返回以下儿童的name属性值。

<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'参数中为第二个文件提供正确的路径。在我的示例中,我使用了“organizations.xml”,但我不知道文件的真实名称或它的位置。 –