这个XSLT
<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 :(得分: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"