执行XSLT转换时出现XPath问题

时间:2016-01-15 04:44:45

标签: xml xslt

我坚持这个问题2天了。我只想提取图像中标记的数据,以便通过XSLT进行转换。我也在这个问题中给出了XML文件。对不起,如果这似乎是一个非常愚蠢的问题。像// PartyInformation / Buyer / Contact // Name这样的类似路径在文档中起作用。但是// PartyInformation / Buyer / Contact //姓名不起作用

到目前为止,我已经尝试过,

  • // PartyInformation /买家/联系/姓名1
  • // PartyInformation /买家/联系//名称
  • /发票[@xmlns:XSD =" HTTP://www.w3.org/2001/XMLSchema"] / PartyInformation [@xmlns =""] /买家/联系[@xmlns =" HTTP://Companydomain.Schema"] /名称[@xmlns =""] /文本()

非常感谢任何帮助!

谢谢。

enter image description here



<?xml version="1.0" encoding="utf-16"?>
<Invoice xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://Companydomain.Schema">
    <InvoiceHeader xmlns="">
        <InvoiceDate />
        <InvoiceDueDate />
        <InvoiceNo />
        <AllowDuplicates>false</AllowDuplicates>
        <AddAttachment>false</AddAttachment>
        <UserApprovedSubmission>false</UserApprovedSubmission>
        <SellerOrderNumber />
        <PurchaseOrderNumber />
        <NumberOfLines>1</NumberOfLines>
        <InvoiceType>
            <Type>ServiceInvoice</Type>
        </InvoiceType>
        <SourceInvoiceType>
            <Type>ServiceInvoice</Type>
        </SourceInvoiceType>
        <DeliveryInformation>
            <DeliveryInstructions />
        </DeliveryInformation>
    </InvoiceHeader>
    <PartyInformation xmlns="">
        <Seller>
            <Party xmlns="http://Companydomain.Schema">
                <PartyId xmlns="" />
                <ExternalSystemId xmlns="" />
                <Name xmlns="" />
                <GBN xmlns="" />
            </Party>
            <Address xmlns="http://Companydomain.Schema" />
        </Seller>
        <Buyer>
            <Party xmlns="http://Companydomain.Schema">
                <PartyId xmlns="">2</PartyId>
                <ExternalSystemId xmlns="" />
                <Name xmlns="" />
                <GBN xmlns="" />
            </Party>
            <Address xmlns="http://Companydomain.Schema" />
            <Contact xmlns="http://Companydomain.Schema">
                <Name xmlns="">Mr Parminder Singh</Name>
                <Phone xmlns="" />
                <Fax xmlns="" />
                <Email xmlns="" />
            </Contact>
            <SuppliersCustomerId />
        </Buyer>
        <ShipTo>
            <Party xmlns="http://Companydomain.Schema">
                <Name xmlns="" />
            </Party>
            <Address xmlns="http://Companydomain.Schema" />
        </ShipTo>
        <ShipFrom>
            <Party xmlns="http://Companydomain.Schema">
                <Name xmlns="" />
            </Party>
            <Address xmlns="http://Companydomain.Schema" />
        </ShipFrom>
        <Payer>
            <Party xmlns="http://Companydomain.Schema">
                <Name xmlns="" />
            </Party>
            <Address xmlns="http://Companydomain.Schema" />
        </Payer>
    </PartyInformation>
</Invoice>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

这是因为Contact节点位于http://Companydomain.Schema命名空间下。尝试:

//PartyInformation/Buyer/*[local-name()='Contact']/Name

或者,您可以在xslt中注册命名空间,

xmlns:com="http://Companydomain.Schema"

并拥有xpath

//PartyInformation/Buyer/com:Contact/Name