2016-09-14 92 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"