XSLT输出为空调试失败,没有输出

问题描述 投票:0回答:1

我通过论坛阅读,我无法理解为什么输出是空的。这可能是我想念的一件简单的事情。

我尝试在VS 2017中进行调试,并且它没有给出任何输出任何帮助,在这件事上表示赞赏。如果我只输入ns0:EFACT_D96A_ORDERS_EAN008节点作为XSLT的输入,则输出带有“测试”内容

    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:ns1="http://Microsoft.LobServices.Sap/2007/03/Types/Idoc/3/ORDERS05//740" xmlns:ns0="http://Microsoft.LobServices.Sap/2007/03/Idoc/3/ORDERS05//740/Send" xmlns:ns2="http://Microsoft.LobServices.Sap/2007/03/Types/Idoc/Common/" xmlns:s0="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006/InterchangeXML">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
      <xsl:template match="/">
        <xsl:apply-templates select="/s0:EFACT_D96A_ORDERS_EAN008" />
      </xsl:template>
      <xsl:template match="/s0:EFACT_D96A_ORDERS_EAN008">

        <ns0:Send>
          <ns0:idocData>
            Test
          </ns0:idocData>
        </ns0:Send>
      </xsl:template>

    </xsl:stylesheet>

输入文件-

    <ins0:EdifactInterchangeXml DelimiterSetSerializedData="39:-1:-1:43:58:63:-1:46:-1" xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006/InterchangeXML">
      <ns0:UNA xmlns:ns0="http://schemas.microsoft.com/Edi/EdifactServiceSchema">
        <UNA1>58</UNA1>

      </ns0:UNA>
      <ns0:UNB xmlns:ns0="http://schemas.microsoft.com/Edi/EdifactServiceSchema">
        <UNB1>
          <UNB1.1>ABCD</UNB1.1>
          <UNB1.2>5</UNB1.2>
        </UNB1>

      </ns0:UNB>
      <TransactionSetGroup>
        <TransactionSet DocType="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006#EFACT_D96A_ORDERS_EAN008">
          <ns0:EFACT_D96A_ORDERS_EAN008 xmlns:ns0="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006">


          </ns0:EFACT_D96A_ORDERS_EAN008>
        </TransactionSet>
      </TransactionSetGroup>
      <ns0:UNZ xmlns:ns0="http://schemas.microsoft.com/Edi/EdifactServiceSchema">
        <UNZ1>1</UNZ1>
        <UNZ2>86</UNZ2>
      </ns0:UNZ>
    </ins0:EdifactInterchangeXml>
xslt xslt-2.0 xslt-grouping
1个回答
0
投票

表达式开头的正斜杠/与文档节点匹配,因此如果select="/s0:EFACT_D96A_ORDERS_EAN008"是文档节点的子节点,那么它只会选择s0:EFACT_D96A_ORDERS_EAN008。即如果它是根元素,它不是。

要选择s0:EFACT_D96A_ORDERS_EAN008而不管它在文档中的位置,请执行此操作...

<xsl:apply-templates select="//s0:EFACT_D96A_ORDERS_EAN008" />

您还需要从匹配表达式中删除单个正斜杠(您不需要匹配表达式中的双斜杠,因为无论元素在文档中的位置如何,匹配都将起作用)

试试这个XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:ns1="http://Microsoft.LobServices.Sap/2007/03/Types/Idoc/3/ORDERS05//740" xmlns:ns0="http://Microsoft.LobServices.Sap/2007/03/Idoc/3/ORDERS05//740/Send" xmlns:ns2="http://Microsoft.LobServices.Sap/2007/03/Types/Idoc/Common/" xmlns:s0="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006/InterchangeXML">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

  <xsl:template match="/">
    <xsl:apply-templates select="//s0:EFACT_D96A_ORDERS_EAN008" />
  </xsl:template>

  <xsl:template match="s0:EFACT_D96A_ORDERS_EAN008">
    <ns0:Send>
      <ns0:idocData>
        Test
      </ns0:idocData>
    </ns0:Send>
  </xsl:template>
</xsl:stylesheet>
© www.soinside.com 2019 - 2024. All rights reserved.