Xml 是否为XSL文档使用多个命名空间?
我有以下XML片段:Xml 是否为XSL文档使用多个命名空间?,xml,xslt,Xml,Xslt,我有以下XML片段: <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Message"> <Header> <MessageId>{11EA62F5-543A-4483-B216-91E526AE2319}</MessageId> &
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Message">
<Header>
<MessageId>{11EA62F5-543A-4483-B216-91E526AE2319}</MessageId>
<SourceEndpoint>SomeSource</SourceEndpoint>
<DestinationEndpoint>SomeDestination</DestinationEndpoint>
</Header>
<Body>
<MessageParts xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Message">
<SalesInvoice xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">
<DocPurpose>Original</DocPurpose>
<SenderId>Me</SenderId>
<CustInvoiceJour class="entity">
<_DocumentHash>ddd70464452c64d5a35dba5ec50cc03a</_DocumentHash>
<Backorder>No</Backorder>
</CustInvoiceJour>
</SalesInvoice>
</MessageInvoice>
</Body>
</Envelope>
在转换后的文档中,会填充
SourceEndpoint
,但不会填充Backorder
,因为它使用不同的命名空间。那么,如何让它使用不同的名称空间呢?您只需在xslt中声明并使用这两个名称空间:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xheader="http://schemas.microsoft.com/dynamics/2008/01/documents/Message"
xmlns:xsales="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice"
exclude-result-prefixes="xheader xsales"
>
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<header>
<name><xsl:value-of select="/*/*/xheader:SourceEndpoint" /></name>
</header>
<body>
<test><xsl:value-of select="/*/*/*/*/*/xsales:Backorder" /></test>
</body>
</xsl:template>
</xsl:stylesheet>
谢谢,但是如果我想从排除结果前缀中同时排除xheader
和xsales
,那该怎么办?只需同时包括这两个-排除结果前缀=“xheader xsales”。我将更新答案以执行此操作。谢谢,出于某种原因,我尝试使用逗号:exclude result prefixes=“xheader,xsales”
!
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xheader="http://schemas.microsoft.com/dynamics/2008/01/documents/Message"
xmlns:xsales="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice"
exclude-result-prefixes="xheader xsales"
>
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<header>
<name><xsl:value-of select="/*/*/xheader:SourceEndpoint" /></name>
</header>
<body>
<test><xsl:value-of select="/*/*/*/*/*/xsales:Backorder" /></test>
</body>
</xsl:template>
</xsl:stylesheet>