2016-09-14 97 views
0

這XSLTXSLT的UBL XML找不到節點值

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" 
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" 
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" 
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Order-2" 
> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:template match="/"> 
    <Things> 
     <Thing AutoReceive="True"> 
     <xsl:value-of select="Order/cbc:ID" /> 
     </Thing> 
    </Things> 
    </xsl:template> 
</xsl:stylesheet> 

針對該XML

<?xml version="1.0" encoding="UTF-8" ?> 
<!-- 
    Unviversal Business Language 2.0 
    http://docs.oasis-open.org/ubl/os-UBL-2.0/UBL-2.0.html 
    http://docs.oasis-open.org/ubl/os-UBL-2.0/xsd/maindoc/UBL-Order-2.0.xsd 
--> 
<Order 
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" 
    xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" 
    xmlns="urn:oasis:names:specification:ubl:schema:xsd:Order-2" 
> 
    <!-- Mx Generated Order Number --> 
    <cbc:ID>8343</cbc:ID> 
</Order> 

找不到節點值。我已經嘗試了很多變體,我已經要求其他三位開發人員來看看它。到目前爲止,我們都無法弄清楚。

<?xml version="1.0" encoding="UTF-8"?> 
<Things xmlns="urn:oasis:names:specification:ubl:schema:xsd:Order-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <Thing AutoReceive="True" /> 
</Things> 

回答

0

Order是一個命名空間,所以你必須通過一個完全合格的名字來稱呼它 - 命名空間分配的前綴後:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" 
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" 
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" 
xmlns:ord="urn:oasis:names:specification:ubl:schema:xsd:Order-2" 
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Order-2"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/"> 
    <Things> 
     <Thing AutoReceive="True"> 
      <xsl:value-of select="ord:Order/cbc:ID" /> 
     </Thing> 
    </Things> 
</xsl:template> 

</xsl:stylesheet> 

這假設您想要得到的結果是在"urn:oasis:names:specification:ubl:schema:xsd:Order-2"命名空間中。


還要注意,在這個例子的目的,這些名稱空間聲明是多餘的:

xmlns:fo="http://www.w3.org/1999/XSL/Format" 
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"