gpt4 book ai didi

xml - XSL 转换后的空标签

转载 作者:行者123 更新时间:2023-12-04 04:44:38 25 4
gpt4 key购买 nike

这是我的 XSL 转换文件:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:Message="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"
xmlns:BankPositivePay="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay">
<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="no"/>
<xsl:template match="/">
<Header>
<records>
<record>
<xsl:value-of select="/BankPositivePay/BankAccountTable/AccountNum"/>
</record>
</records>
</Header>
</xsl:template>
</xsl:stylesheet>

输入的xml文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<Header>
<MessageId>{A604C46E-F3E3-4BCB-9F7A-E8FD8749A7FC}</MessageId>
<Action>http://tempuri.org/BankPositivePayService/find</Action>
</Header>
<Body>
<MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<BankPositivePay xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay">
<BankAccountTable class="entity">
<AccountID>USA OPER</AccountID>
<AccountNum>34567</AccountNum>
<CurrencyCode>USD</CurrencyCode>
<LedgerDimension>
<MainAccount xmlns="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes">110110</MainAccount>
</LedgerDimension>
<BankChequeTable class="entity">
<AccountID>USA OPER</AccountID>
<AmountCur>3500.00</AmountCur>
<ChequeNum>1132</ChequeNum>
<ChequeStatus>Payment</ChequeStatus>
<RecipientAccountNum>1001</RecipientAccountNum>
<TransDate>2013-08-16</TransDate>
<VendTable class="entity">
<Currency>USD</Currency>
<DefaultDimension>
<Values xmlns="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes">
<Value>
<Name>CustomDepartment</Name>
<Value>060</Value>
</Value>
</Values>
</DefaultDimension>
<VendGroup>10</VendGroup>
</VendTable>
<CompanyInfo xsi:type="AxdEntity_CompanyInfo_CompanyInfo" class="entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DataArea>ceu</DataArea>
</CompanyInfo>
</BankChequeTable>
</BankAccountTable>
</BankPositivePay>
</MessageParts>
</Body>
</Envelope>

问题是我得到的输出为:
<?xml version="1.0" encoding="utf-8"?>
<Header xmlns:Message="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" xmlns:BankPositivePay="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay">
<records>
<record></record>
</records>
</Header>

记录元素是空的,但它应该返回 AccountNum 34567。感谢任何帮助。谢谢。

最佳答案

您的选择表达式有两个问题:

  • 您没有在路径中使用命名空间。
  • 你没有找到你想要的节点

  • 命名空间问题在这里经常出现。以具有非空 namespace URI 的节点为目标的 XPath 选择器的每一步都必须带有前缀(如果您使用名称选择器将其作为目标)。

    如果你改变表达
    <xsl:value-of select="/BankPositivePay/BankAccountTable/AccountNum"/>


    <xsl:value-of select="//BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:AccountNum"/>

    那么你的输出将是
    <Header xmlns:Message="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" xmlns:BankPositivePay="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay">
    <records>
    <record>34567</record>
    </records>
    </Header>

    需要 // 因为您的目标元素不在根。 // 通常被避免,因为它“昂贵”;您如何准确定位该节点取决于您的要求。

    关于xml - XSL 转换后的空标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18383319/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com