2016-10-27 14 views
0

XSLファイルに別の名前空間からの追加要素を追加する私たちは、以下のスタイルシート内の別の名前空間を使用して、追加要素を追加しようとしている

これはのレンダリングされたコピーにXMLファイルからデータを取得するために使用されます請求書。

要素はので、私は追加の一つとして、それを追加しました次の名前空間使用しています:

xmlns:f="http://services.finance.com/schema/finbwSchemaLib/2005/05/13" 

「バットのRegいいえ」と呼ばれる追加の要素に追加するには、私はdiv要素に追加しました:

<td width="25%">VATReg</td> 

そしてIは、追加の名前空間「F」に対応するテンプレート照合部内の要素のための値に追加されました:

<xsl:value-of select="f:VatRegNo"/> 

ただし、スタイルシートでXML請求書を取得しても、この値は取得されません。 XMLファイルに付加価値税が含まれています。

この追加要素を追加するための項目がありますか?

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fin="http://services.finance.com/schema/finbwInvoice/2006/11/20" xmlns:finlib="http://services.finance.com/schema/finbwSchemaLib/2006/11/20" xmlns:f="http://services.finance.com/schema/finbwSchemaLib/2005/05/13" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2004/10/xpath-functions" xmlns:xdt="http://www.w3.org/2004/10/xpath-datatypes"> 
    <xsl:template match="/"> 
     <HTML> 
      <head> 
       <title>finance INVOICE</title> 
       <style><![CDATA[ 
       TD { 
        VERTICAL-ALIGN: top; 
       } 

       .heading { 
        font-family:Arial,Helvetica,sans-serif; 
        font-size:14pt; 
        font-weight:bold; 
        margin-top:12pt; 
        margin-bottom:12pt; 
       } 

       .address { 
        font-size:10pt; 
        font-family:Arial,Helvetica,sans-serif; 
       } 

       .narrative { 
        font-style:italic; 
       } 

       .delivsched{ 
        font-size:10pt; 
       } 
      ]]></style> 
      </head> 
      <body> 
       <xsl:apply-templates select="//fin:finbwInvoice"/> 
      </body> 
     </HTML> 
    </xsl:template> 
    <xsl:template match="fin:finbwInvoice"> 
     <xsl:apply-templates select="fin:Invoice"/> 
    </xsl:template> 
    <xsl:template match="fin:Invoice"> 
     <div align="left"> 
      <!-- ================= --> 
      <!-- INVOICE addresses --> 
      <!-- ================= --> 
      <table border="0" width="100%"> 
       <tr> 
        <td width="32%" height="23" valign="top"> 
         <b/>Invoice To:</td> 
        <td width="1%" height="150" valign="top" rowspan="2"/> 
        <td width="33%" height="23" valign="top"> 
         <b/>Payment To:</td> 
        <td width="1%" height="150" valign="top" rowspan="2"/> 
        <td width="32%" height="23" valign="top"> 
         <b/>Deliver To:</td> 
       </tr> 
       <tr> 
        <td valign="top" bgcolor="#C0C0C0"> 
         <xsl:apply-templates select="fin:Header/fin:BillTo"/> 
        </td> 
        <td valign="top" bgcolor="#C0C0C0"> 
         <xsl:apply-templates select="fin:Header/fin:Seller"/> 
        </td> 
        <td valign="top" bgcolor="#C0C0C0"> 
         <xsl:apply-templates select="fin:Header/fin:ShipTo"/> 
        </td> 
       </tr> 
      </table> 
      <br/> 
      <!-- ============================= --> 
      <!-- INVOICE text --> 
      <!-- ============================= --> 
      <p> 
      <td width="15%">Invoice Text: </td> 
      <td> 
       <xsl:value-of select="fin:Header/fin:InvoiceText"/> 
        </td> 
      </p> 
      <!-- ============================= --> 
      <!-- INVOICE dates, references etc --> 
      <!-- ============================= --> 
      <table border="1" width="100%" height="68" bordercolor="black"> 
       <tr bgcolor="#000000" style="color:white;font-size:10pt;font-family:Tahoma;font-weight:bold"> 
        <td width="15%">Date</td> 
        <td width="15%">Invoice number</td> 
        <td width="15%">PO number</td> 
        <td width="20%">Our Ref</td> 
        <td width="20%">Your Ref</td> 
        <td width="15%">Delivery Method</td> 
       </tr> 
       <tr> 
        <td> 
         <xsl:value-of select="fin:Header/finlib:InvoiceDate"/> 
        </td> 
        <td> 
         <xsl:value-of select="fin:InvoiceNo"/> 
        </td> 
        <td> 
         <xsl:value-of select="fin:Header/fin:OrderRef"/> 
        </td> 
        <td> 
         <xsl:value-of select="fin:Header/fin:Seller/fin:Contact"/> 
        </td> 
        <td> 
         <xsl:value-of select="fin:Header/fin:Buyer/fin:Accountable"/> 
        </td> 
        <td> 
         <xsl:value-of select="fin:Header/fin:DeliveryInfo/fin:DelivMethodDescr"/> 
        </td> 
       </tr> 
      </table> 
      <br/> 
      <!-- ============= --> 
      <!-- INVOICE lines --> 
      <!-- ============= --> 
      <table border="0" width="100%" height="108" cellpadding="5"> 
       <tr bgcolor="#C0C0C0" style="font-size:10pt;font-family:Tahoma"> 
        <td align="left">Article</td> 
        <td align="left">Description</td> 
        <td align="left">Unit</td> 
        <td align="right">Quantity</td> 
        <td align="right">Price</td> 
        <td align="right">Discount%</td> 
        <td align="right">Amount</td> 
       </tr> 
       <xsl:apply-templates select="fin:Details/fin:Detail"/> 
      </table> 
      <!-- =============== --> 
      <!-- INVOICE tax details --> 
      <!-- =============== --> 
      <table border="0" width="50%" height="68" bordercolor="black"> 
       <tr bgcolor="#000000" style="color:white;font-size:10pt;font-family:Tahoma;font-weight:bold"> 
        <td width="25%">Tax %</td> 
        <td width="25%">Total excl tax</td> 
        <td width="25%">Tax</td> 
      <td width="25%">VATReg</td> 
       </tr> 
       <xsl:apply-templates select="fin:Details/fin:Detail/fin:TaxDetails"/> 
      </table> 
      <br/> 
      <!-- ============= --> 
      <!-- INVOICE total --> 
      <!-- ============= --> 
      <table border="0" width="100%"> 
       <tr> 
        <td width="90%" align="right">Total excl tax</td> 
        <td width="10%" align="right"> 
         <xsl:value-of select="fin:Summary/fin:TotalExclTax"/> 
        </td> 
       </tr> 
       <tr> 
        <td align="right">Tax</td> 
        <td width="10%" align="right"> 
         <xsl:value-of select="fin:Summary/fin:TotalTax"/> 
        </td> 
       </tr> 
       <tr> 
        <td align="right">Total in <xsl:value-of select="fin:Header/fin:Currency"/> 
        </td> 
        <td width="10%" align="right"> 
         <xsl:value-of select="fin:Summary/fin:TotalInclTax"/> 
        </td> 
       </tr> 
      </table> 
     </div> 
    </xsl:template> 
    <!-- "INVOICE" --> 
    <xsl:template match="fin:Detail"> 
     <tr> 
      <td align="left"> 
       <xsl:value-of select="fin:Products/fin:SellerProductCode"/> 
      </td> 
      <td align="left"> 
       <xsl:value-of select="fin:Products/fin:SellerProductDescr"/> 
      </td> 
      <td align="left"> 
       <xsl:value-of select="fin:Products/finlib:UnitCode"/> 
      </td> 
      <td align="right"> 
       <xsl:value-of select="fin:Products/finlib:Quantity"/> 
      </td> 
      <td align="right"> 
       <xsl:value-of select="fin:Products/fin:Price"/> 
      </td> 
      <td align="right"> 
       <xsl:value-of select="finlib:DiscountPct"/> 
      </td> 
      <td align="right"> 
       <xsl:value-of select="fin:LineTotExclTax"/> 
      </td> 
     </tr> 
    </xsl:template> 
    <xsl:template match="fin:TaxDetails"> 
     <tr> 
      <td align="left"> 
       <xsl:value-of select="fin:TaxPercent"/> 
      </td> 
      <td align="right"> 
       <xsl:value-of select="fin:LineTotExclTax"/> 
      </td> 
      <td align="right"> 
       <xsl:value-of select="fin:TaxAmount"/> 
      </td> 
     <td align="right"> 
       <xsl:value-of select="f:VatRegNo"/> 
      </td> 
     </tr> 
    </xsl:template> 
    <xsl:template match="fin:Seller|fin:BillTo|fin:ShipTo"> 
     <SPAN class="finlibaddress"> 
      <DIV> 
       <xsl:value-of select="finlib:Name"/> 
      </DIV> 
      <DIV> 
       <xsl:value-of select="finlib:AddressInfo/finlib:Address"/> 
      </DIV> 
      <DIV> 
       <xsl:value-of select="finlib:AddressInfo/finlib:ZipCode"/> 
       <xsl:value-of select="finlib:AddressInfo/finlib:Place"/> 
      </DIV> 
      <DIV> 
       <xsl:value-of select="finlib:AddressInfo/finlib:Country"/> 
      </DIV> 
     </SPAN> 
    </xsl:template> 
    <!-- "Address" --> 
</xsl:stylesheet> 

これは、以下のXMLファイルである:

<?xml version="1.0" encoding="UTF-8"?><finbwInvoice xmlns="http://services.fin.com/schema/finbwInvoice/2006/11/20" xmlns:finlib="http://services.fin.com/schema/finbwSchemaLib/2006/11/20" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://services.fin.com/schema/finbwInvoice/2006/11/20 http://services.fin.com/schema/finbwInvoice/2006/11/20/finbwInvoice.xsd"> 
    <Invoice> 
    <InvoiceNo>Invoice_Number</InvoiceNo> 
    <Header> 
     <finlib:InvoiceDate>2016-08-22</finlib:InvoiceDate> 
     <OrderRef>123456789</OrderRef> 
     <OrderNo>0</OrderNo> 
     <finlib:ContractId/> 
     <ArchivePath/> 
     <Currency>GBP</Currency> 
     <Seller> 
     <finlib:Name>Seller Name</finlib:Name> 
     <finlib:AddressInfo> 
      <finlib:Address>01 Address</finlib:Address> 
      <finlib:Place>Place</finlib:Place> 
      <finlib:Province>Province</finlib:Province> 
      <finlib:ZipCode>AB1 2DC</finlib:ZipCode> 
     </finlib:AddressInfo> 
     <finlib:CompRegNo/> 
     <finlib:VatRegNo>GB12345678</finlib:VatRegNo> 
     <finlib:SellerNo>1234567</finlib:SellerNo> 
     </Seller> 
     <BillTo> 
     <finlib:Name>Buyer Name</finlib:Name> 
     <finlib:AddressInfo> 
      <finlib:Address>02 Address</finlib:Address> 
      <finlib:Place>Place</finlib:Place> 
      <finlib:ZipCode>XY9 8UV</finlib:ZipCode> 
     </finlib:AddressInfo> 
     </BillTo> 
     <finlib:ReferenceCode> 
     <finlib:Code/> 
     <finlib:Value/> 
     </finlib:ReferenceCode> 
    </Header> 
    <Details> 
     <Detail> 
     <LineNo>2</LineNo> 
     <finlib:TransDate>2016-08-22</finlib:TransDate> 
     <LineTotExclTax>1000.00</LineTotExclTax> 
     <TaxPercent>20.00</TaxPercent> 
     <TaxAmount>212.80</TaxAmount> 
     <LineTotInclTax>1276.80</LineTotInclTax> 
     <finlib:TaxCode>V</finlib:TaxCode> 
     <Products> 
      <SellerProductCode>AAA1A222AD</SellerProductCode> 
      <SellerProductDescr>Seller Product Description</SellerProductDescr> 
      <finlib:UnitCode>UN</finlib:UnitCode> 
      <finlib:Quantity>1.00</finlib:Quantity> 
      <Price>1064.00</Price> 
     </Products> 
     </Detail> 
     <Detail> 
     <LineNo>1</LineNo> 
     <finlib:TransDate>2016-08-22</finlib:TransDate> 
     <LineTotExclTax>572.00</LineTotExclTax> 
     <TaxPercent>20.00</TaxPercent> 
     <TaxAmount>114.40</TaxAmount> 
     <LineTotInclTax>686.40</LineTotInclTax> 
     <finlib:TaxCode>V</finlib:TaxCode> 
     <Products> 
      <SellerProductCode>41415</SellerProductCode> 
      <SellerProductDescr>Product Description</SellerProductDescr> 
      <finlib:UnitCode>UN</finlib:UnitCode> 
      <finlib:Quantity>1.00</finlib:Quantity> 
      <Price>572.00</Price> 
     </Products> 
     </Detail> 
    </Details> 
    <Summary> 
     <TotalExclTax>1636.00</TotalExclTax> 
     <TotalTax>327.20</TotalTax> 
     <TotalInclTax>1963.20</TotalInclTax> 
    </Summary> 
    </Invoice> 
</finbwInvoice> 

これは、XMLファイルのすべての要素を使用してレンダリングインボイスのHTMLファイルを生成するために、スタイルシートを使用して処理されます。

+0

入出力サンプルを添付することはできますか? – Rao

+0

''があなたのスタイルシートに表示されるところはありません。 XML入力が表示されないので、スタイルシートがその値を取得する方法を伝えます。 –

+0

申し訳ありません - 私はその値を表示するように修正しました – user3565164

答えて

0

間違って:エレメントVatRegNoは、f -namespaceにありません。

ソースドキュメントでは、要素(VatRegNo)は名前空間http://services.fin.com/schema/finbwSchemaLib/2006/11/20にあります。

これを選択するには、そのURIに接頭辞をバインドして呼び出します。

rootnodeにxmlns:finlib="http://services.fin.com/schema/finbwSchemaLib/2006/11/20"を追加し、コンテキストノードで要素を尊重してfinlib:VatRegNo経由で呼び出すことができます。

関連する問題