首页 > 解决方案 > XSLT 输出为空 调试失败,无输出

问题描述

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

我尝试在 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>

标签: xsltxslt-2.0xslt-grouping

解决方案


/表达式开头的正斜杠与文档节点匹配,因此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>

推荐阅读