简体   繁体   English

Visual Studio生成的测试XML和XSLT模式映射引发错误:XML文档必须包含根级元素

[英]Visual studio generated test XML and XSLT schema mapping throws an error : XML document must contain a root level element

maybe someone has an answer or idea. 也许有人有答案或想法。 Thank you. 谢谢。

This is to debug a custom XSLT mapping in a deployed Biztalk Server app. 这是为了在已部署的Biztalk Server应用程序中调试自定义XSLT映射。 I get errors with it and it's not easy to track what is going wrong. 我对此有误,要跟踪出什么问题并不容易。 BTW, maybe it's not necessary to fully understand Biztalk at all here, because it's mostly an XML, XSLT related issue, I guess. 顺便说一句,我猜这里也许根本不需要完全了解Biztalk,因为它主要是与XML,XSLT相关的问题。

So, I went back to the basics and I generated a very simple XSLT from a map that works in the deployed app and I wanted to visually see the result in an XML output directly in Visual Studio. 因此,我回到基础知识,并从可在已部署应用程序中使用的地图生成了一个非常简单的XSLT,我想在Visual Studio中直接在XML输出中直观地看到结果。 From there I thought I could experiment with my custom XSLT and determine and fix the errors more easily than in the deployed Biztalk app (log is not totally helpful). 从那里开始,我认为我可以尝试使用自定义的XSLT,比在已部署的Biztalk应用程序中更容易地确定和修复错误(日志并不完全有帮助)。

So here what I have done, if it makes sense : (see code below as required - sorry I had to trim the code a bit to fit in the post) 所以在这里,如果可以的话,我做了什么:(请参阅下面的代码-抱歉,我不得不对代码进行一些调整以适合帖子)

In Visual Studio 2012 Ultimate, 在Visual Studio 2012 Ultimate中,

  1. I have this XSLT that I generated from a functional Biztalk Server map (validate map command). 我有从功能正常的Biztalk Server映射(验证映射命令)生成的XSLT。 The map has a Biztalk HL7 accelerator ADT_A01_25_GLO_DEF xsd schema on the left (input), and our custom output schema on the right; 该映射在左侧(输入)具有Biztalk HL7加速器ADT_A01_25_GLO_DEF xsd架构,在右侧具有我们的自定义输出架构。 This is for and incoming message. 这是用于和传入消息。

  2. I generated a test file (generate instance command) from the ADT_A01_25_GLO_DEF xsd schema as a source XML file to test the XSLT; 我从ADT_A01_25_GLO_DEF xsd模式生成了一个测试文件(生成实例命令),作为测试XSLT的源XML文件。

  3. I selected that XML file as the input for the XSLT to process in VS; 我选择了该XML文件作为XSLT在VS中处理的输入。

  4. I process that file with the command in menu XML / Start XSLT without debugging, and Visual studio gives me just one error : 我使用菜单XML / Start XSLT中的命令处理该文件,而无需进行调试,而Visual Studio仅给我一个错误:

XML document must contain a root level element. XML文档必须包含一个根级元素。

(The output file is actually empty) (输出文件实际上为空)

Any idea on what I'm missing please? 对我想念的东西有任何想法吗?

Thanks 谢谢

Claude 克劳德

Biztalk accelarator Hl7 ADT_A01_25_GLO_DEF xsd schema on the left : 左侧的Biztalk加速器Hl7 ADT_A01_25_GLO_DEF xsd架构:

 <?xml version="1.0" encoding="utf-16" ?> 
    - <xs:schema xmlns="http://microsoft.com/HealthCare/HL7/2X" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:ns0="http://microsoft.com/HealthCare/HL7/2X/2.5/Segments" targetNamespace="http://microsoft.com/HealthCare/HL7/2X" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:import schemaLocation="BTAHL7Schemas.segments_25" namespace="http://microsoft.com/HealthCare/HL7/2X/2.5/Segments" /> 
    - <xs:annotation>
    - <xs:appinfo>
      <b:schemaInfo standards_version="HL7.DBVersion.1_5" document_type="HL7 2X Schema" version="2.0.0104.0.2.0" root_reference="ADT_A01_25_GLO_DEF" /> 
    - <b:references>
      <b:reference targetNamespace="http://microsoft.com/HealthCare/HL7/2X/2.5/DataTypes" /> 
      <b:reference targetNamespace="http://microsoft.com/HealthCare/HL7/2X/2.5/Segments" /> 
      <b:reference targetNamespace="http://microsoft.com/HealthCare/HL7/2X/2.5/Tables" /> 
      </b:references>
      </xs:appinfo>
      </xs:annotation>
    - <xs:element name="ADT_A01_25_GLO_DEF">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="SFT_SoftwareSegment" type="ns0:SFT" /> 
      <xs:element minOccurs="1" maxOccurs="1" name="EVN_EventType" type="ns0:EVN" /> 
      <xs:element minOccurs="1" maxOccurs="1" name="PID_PatientIdentification" type="ns0:PID" /> 
      <xs:element minOccurs="0" maxOccurs="1" name="PD1_PatientAdditionalDemographic" type="ns0:PD1" /> 
      <xs:element minOccurs="0" maxOccurs="unbounded" name="ROL_Role" type="ns0:ROL" /> 
      <xs:element minOccurs="0" maxOccurs="unbounded" name="NK1_NextOfKinAssociatedParties" type="ns0:NK1" /> 
      <xs:element minOccurs="1" maxOccurs="1" name="PV1_PatientVisit" type="ns0:PV1" /> 
      <xs:element minOccurs="0" maxOccurs="1" name="PV2_PatientVisitAdditionalInformation" type="ns0:PV2" /> 
 ....snip....


  <xs:element minOccurs="0" maxOccurs="1" name="PDA_PatientDeathAndAutopsy" type="ns0:PDA" /> 


 </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:schema>

XML instance generated in Visusal studio from schema, trimmed, with some data 在Visusal Studio中从模式中裁剪的XML实例(带有一些数据)

<?xml version="1.0" encoding="utf-16" ?>
<root>
  <PID_PatientIdentification>
    <PID_1_SetIdPid>PID_1_SetIdPid_0</PID_1_SetIdPid>

 ....snip....

<PID_3_PatientIdentifierList>
  <CX_0_IdNumber>1</CX_0_IdNumber>
  <CX_1_CheckDigit>CX_1_CheckDigit_0</CX_1_CheckDigit>
  <CX_2_CheckDigitScheme>CX_2_CheckDigitScheme_0</CX_2_CheckDigitScheme>
  <CX_3_AssigningAuthority>
    <CX_3_0_NamespaceId>CX_3_0_NamespaceId_0</CX_3_0_NamespaceId>
    <CX_3_1_UniversalId>CX_3_1_UniversalId_0</CX_3_1_UniversalId>
    <CX_3_2_UniversalIdType>CX_3_2_UniversalIdType_0</CX_3_2_UniversalIdType>
  </CX_3_AssigningAuthority>
  <CX_4_IdentifierTypeCode>SSN</CX_4_IdentifierTypeCode>
  <CX_5_AssigningFacility>
    <CX_5_0_NamespaceId>CX_5_0_NamespaceId_0</CX_5_0_NamespaceId>
    <CX_5_1_UniversalId>CX_5_1_UniversalId_0</CX_5_1_UniversalId>
    <CX_5_2_UniversalIdType>CX_5_2_UniversalIdType_0</CX_5_2_UniversalIdType>
  </CX_5_AssigningFacility>
  <CX_6_EffectiveDate>CX_6_EffectiveDate_0</CX_6_EffectiveDate>
  <CX_7_ExpirationDate>CX_7_ExpirationDate_0</CX_7_ExpirationDate>
  <CX_8_AssigningJurisdiction>
    <CX_8_0_Identifier>CX_8_0_Identifier_0</CX_8_0_Identifier>
    <CX_8_1_Text>CX_8_1_Text_0</CX_8_1_Text>
    <CX_8_2_NameOfCodingSystem>CX_8_2_NameOfCodingSystem_0</CX_8_2_NameOfCodingSystem>
    <CX_8_3_AlternateIdentifier>CX_8_3_AlternateIdentifier_0</CX_8_3_AlternateIdentifier>
    <CX_8_4_AlternateText>CX_8_4_AlternateText_0</CX_8_4_AlternateText>

 ....snip....

  </PID_PatientIdentification>


 ....snip....

</root>

XSLT generated from working Biztalk map : 从工作Biztalk映射生成的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 s1 s2 s3 s4 userCSharp" 
                version="1.0" 
                xmlns:s0="http://schemas.microsoft.com/BizTalk/2003/aggschema" 
                xmlns:s1="http://microsoft.com/HealthCare/HL7/2X/2.5/Tables" 
                xmlns:s2="http://microsoft.com/HealthCare/HL7/2X" 
                xmlns:s3="http://microsoft.com/HealthCare/HL7/2X/2.5/Segments" 
                xmlns:s4="http://microsoft.com/HealthCare/HL7/2X/2.5/DataTypes" 
                xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
  <xsl:template match="/">
    <xsl:apply-templates select="/s0:Root" />
  </xsl:template>
  <xsl:template match="/s0:Root">
    <form1>
      <xsl:if test="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.3_SendingApplication/HD.0_NamespaceId">
        <MSH_3-SendingApplication>
          <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.3_SendingApplication/HD.0_NamespaceId/text()" />
        </MSH_3-SendingApplication>
      </xsl:if>
      <xsl:if test="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.4_SendingFacility/HD.0_NamespaceId">
        <MSH_4-SendingFacility>
          <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.4_SendingFacility/HD.0_NamespaceId/text()" />
        </MSH_4-SendingFacility>
      </xsl:if>
      <xsl:if test="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.5_ReceivingApplication/HD.0_NamespaceId">
        <MSH_5-ReceiveApplication>
          <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.5_ReceivingApplication/HD.0_NamespaceId/text()" />
        </MSH_5-ReceiveApplication>
      </xsl:if>
      <xsl:if test="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.6_ReceivingFacility/HD.0_NamespaceId">
        <MSH_6-ReceiveFacility>
          <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.6_ReceivingFacility/HD.0_NamespaceId/text()" />
        </MSH_6-ReceiveFacility>
      </xsl:if>
      <xsl:if test="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.9_MessageType/CM_MSG.0_MessageType">
        <MSH_9-MessageType>
          <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.9_MessageType/CM_MSG.0_MessageType/text()" />
        </MSH_9-MessageType>
      </xsl:if>
      <xsl:if test="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.9_MessageType/CM_MSG.1_TriggerEvent">
        <MSH_9-EventTrigger>
          <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.9_MessageType/CM_MSG.1_TriggerEvent/text()" />
        </MSH_9-EventTrigger>
      </xsl:if>
      <MSH_10-MessageControlID>
        <xsl:value-of select="InputMessagePart_0/s2:MSH_25_GLO_DEF/MSH/MSH.10_MessageControlId/text()" />
      </MSH_10-MessageControlID>
      <xsl:variable name="var:v1" select="userCSharp:MyConcat()" />
      <EventTimeStamp>
        <xsl:value-of select="$var:v1" />
      </EventTimeStamp>
      <xsl:variable name="var:v2" select="userCSharp:TSTime()" />
      <PID_33-ApplicationDate>
        <xsl:value-of select="$var:v2" />
      </PID_33-ApplicationDate>
      <xsl:for-each select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_3_PatientIdentifierList">
        <PID_3_PatientIdentifierList>
          <xsl:if test="CX_0_IdNumber">
            <IdNumber>
              <xsl:value-of select="CX_0_IdNumber/text()" />
            </IdNumber>
          </xsl:if>
          <xsl:if test="CX_4_IdentifierTypeCode">
            <IdentifierTypeCode>
              <xsl:value-of select="CX_4_IdentifierTypeCode/text()" />
            </IdentifierTypeCode>
          </xsl:if>
        </PID_3_PatientIdentifierList>
      </xsl:for-each>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_5_PatientName/XPN_0_FamilyName/XPN_0_0_Surname">
        <PID_5-LastName>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_5_PatientName/XPN_0_FamilyName/XPN_0_0_Surname/text()" />
        </PID_5-LastName>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_5_PatientName/XPN_1_GivenName">
        <PID_5-FirstName>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_5_PatientName/XPN_1_GivenName/text()" />
        </PID_5-FirstName>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_7_DateTimeOfBirth/TS_0_Time">
        <PID_7-BirthDate>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_7_DateTimeOfBirth/TS_0_Time/text()" />
        </PID_7-BirthDate>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_15_PrimaryLanguage/CE_0_Identifier">
        <PID_15-PreferredLanguage>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_15_PrimaryLanguage/CE_0_Identifier/text()" />
        </PID_15-PreferredLanguage>
      </xsl:if>
      <xsl:variable name="var:v3" select="userCSharp:ConvertSex(string(InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_8_AdministrativeSex/text()))" />
      <PID_8-Sex>
        <xsl:value-of select="$var:v3" />
      </PID_8-Sex>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_13_PhoneNumberHome/XTN_0_TelephoneNumber">
        <PID_13-HomePhone>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_13_PhoneNumberHome/XTN_0_TelephoneNumber/text()" />
        </PID_13-HomePhone>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_14_PhoneNumberBusiness/XTN_0_TelephoneNumber">
        <PID_14-WorkPhone>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_14_PhoneNumberBusiness/XTN_0_TelephoneNumber/text()" />
        </PID_14-WorkPhone>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_0_StreetAddress/XAD_0_0_StreetOrMailingAddress">
        <PID_11-Address>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_0_StreetAddress/XAD_0_0_StreetOrMailingAddress/text()" />
        </PID_11-Address>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_2_City">
        <PID_11-City>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_2_City/text()" />
        </PID_11-City>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_3_StateOrProvince">
        <PID_11-IDState>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_3_StateOrProvince/text()" />
        </PID_11-IDState>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_4_ZipOrPostalCode">
        <PID_11-ZIPCode>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_11_PatientAddress/XAD_4_ZipOrPostalCode/text()" />
        </PID_11-ZIPCode>
      </xsl:if>
      <xsl:if test="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_13_PhoneNumberHome/XTN_3_EmailAddress">
        <Email>
          <xsl:value-of select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/PID_PatientIdentification/PID_13_PhoneNumberHome/XTN_3_EmailAddress/text()" />
        </Email>
      </xsl:if>
      <xsl:for-each select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/NK1_NextOfKinAssociatedParties">
        <xsl:for-each select="NK1_2_Name">
          <xsl:for-each select="XPN_0_FamilyName">
            <Nk1>
              <NK1_1-SetID>
                <xsl:value-of select="../../NK1_1_SetIdNk1/text()" />
              </NK1_1-SetID>
              <NK1_2-DelegateLastName>
                <xsl:value-of select="./text()" />
              </NK1_2-DelegateLastName>
              <xsl:if test="../XPN_1_GivenName">
                <NK1_2-DelegateFirstName>
                  <xsl:value-of select="../XPN_1_GivenName/text()" />
                </NK1_2-DelegateFirstName>
              </xsl:if>
              <xsl:if test="../../NK1_3_Relationship/CE_0_Identifier">
                <NK1_3-IDDelegateRelationship>
                  <xsl:value-of select="../../NK1_3_Relationship/CE_0_Identifier/text()" />
                </NK1_3-IDDelegateRelationship>
              </xsl:if>
              <xsl:if test="../../NK1_5_PhoneNumber/XTN_0_TelephoneNumber">
                <NK1_5-DelegateHomePhone>
                  <xsl:value-of select="../../NK1_5_PhoneNumber/XTN_0_TelephoneNumber/text()" />
                </NK1_5-DelegateHomePhone>
              </xsl:if>
              <xsl:if test="../../NK1_5_PhoneNumber/XTN_3_EmailAddress">
                <NK1_5-DelegateEmail>
                  <xsl:value-of select="../../NK1_5_PhoneNumber/XTN_3_EmailAddress/text()" />
                </NK1_5-DelegateEmail>
              </xsl:if>
              <xsl:if test="../../NK1_6_BusinessPhoneNumber/XTN_0_TelephoneNumber">
                <NK1_6-DelegateWorkPhone>
                  <xsl:value-of select="../../NK1_6_BusinessPhoneNumber/XTN_0_TelephoneNumber/text()" />
                </NK1_6-DelegateWorkPhone>
              </xsl:if>
            </Nk1>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:for-each>
      <xsl:for-each select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/AL1_PatientAllergyInformation">
        <AL1_PatientAllergy>
          <AL1_1-SetID>
            <xsl:value-of select="AL1_1_SetIdAl1/text()" />
          </AL1_1-SetID>
          <xsl:if test="AL1_2_AllergenTypeCode/CE_0_Identifier">
            <AL1_2-AllergenTypeCode>
              <xsl:value-of select="AL1_2_AllergenTypeCode/CE_0_Identifier/text()" />
            </AL1_2-AllergenTypeCode>
          </xsl:if>
          <xsl:if test="AL1_3_AllergenCodeMnemonicDescription/CE_0_Identifier">
            <AL1_3-AllergyDescription>
              <xsl:value-of select="AL1_3_AllergenCodeMnemonicDescription/CE_0_Identifier/text()" />
            </AL1_3-AllergyDescription>
          </xsl:if>
          <xsl:if test="AL1_4_AllergySeverityCode/CE_0_Identifier">
            <AL1_4-Severity>
              <xsl:value-of select="AL1_4_AllergySeverityCode/CE_0_Identifier/text()" />
            </AL1_4-Severity>
          </xsl:if>
        </AL1_PatientAllergy>
      </xsl:for-each>
      <xsl:for-each select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/OBX_ObservationResult">
        <xsl:for-each select="OBX_5_ObservationValue">
          <OBX_ObservationResult>
            <xsl:if test="../OBX_1_SetIdObx">
              <OBX_1_SetIDObx>
                <xsl:value-of select="../OBX_1_SetIdObx/text()" />
              </OBX_1_SetIDObx>
            </xsl:if>
            <xsl:if test="../OBX_2_ValueType">
              <OBX_2_ValueType>
                <xsl:value-of select="../OBX_2_ValueType/text()" />
              </OBX_2_ValueType>
            </xsl:if>
            <xsl:if test="../OBX_3_ObservationIdentifier/CE_0_Identifier">
              <OBX_3_ObservationIdentifier>
                <xsl:value-of select="../OBX_3_ObservationIdentifier/CE_0_Identifier/text()" />
              </OBX_3_ObservationIdentifier>
            </xsl:if>
            <xsl:if test="../OBX_3_ObservationIdentifier/CE_1_Text">
              <OBX_3_Text>
                <xsl:value-of select="../OBX_3_ObservationIdentifier/CE_1_Text/text()" />
              </OBX_3_Text>
            </xsl:if>
            <OBX_5_ObservationValue>
              <xsl:value-of select="./text()" />
            </OBX_5_ObservationValue>
            <xsl:if test="../OBX_6_Units/CE_1_Text">
              <OBX_6_Units>
                <xsl:value-of select="../OBX_6_Units/CE_1_Text/text()" />
              </OBX_6_Units>
            </xsl:if>
            <OBX_11_ObservationResultStatus>
              <xsl:value-of select="../OBX_11_ObservationResultStatus/text()" />
            </OBX_11_ObservationResultStatus>
            <xsl:if test="../OBX_14_DateTimeOfTheObservation">
              <OBX_14_DataTimeOfTheObservation>
                <xsl:value-of select="../OBX_14_DateTimeOfTheObservation/text()" />
              </OBX_14_DataTimeOfTheObservation>
            </xsl:if>
          </OBX_ObservationResult>
        </xsl:for-each>
      </xsl:for-each>
      <xsl:for-each select="InputMessagePart_1/s2:ADT_A01_25_GLO_DEF/DG1_Diagnosis">
        <xsl:for-each select="DG1_3_DiagnosisCodeDg1">
          <DG1_Diagnosis>
            <xsl:if test="CE_0_Identifier">
              <DG1_3_DiagnosisCodeDG1>
                <xsl:value-of select="CE_0_Identifier/text()" />
              </DG1_3_DiagnosisCodeDG1>
            </xsl:if>
            <xsl:if test="../DG1_4_DiagnosisDescription">
              <DG1_4_DiagnosisDescription>
                <xsl:value-of select="../DG1_4_DiagnosisDescription/text()" />
              </DG1_4_DiagnosisDescription>
            </xsl:if>
            <xsl:if test="../DG1_5_DiagnosisDateTime/TS_0_Time">
              <DG1_5_DiagnosticDateTime>
                <xsl:value-of select="../DG1_5_DiagnosisDateTime/TS_0_Time/text()" />
              </DG1_5_DiagnosticDateTime>
            </xsl:if>
            <DG1_6_DiagnosticType>
              <xsl:value-of select="../DG1_6_DiagnosisType/text()" />
            </DG1_6_DiagnosticType>
          </DG1_Diagnosis>
        </xsl:for-each>
      </xsl:for-each>
    </form1>
  </xsl:template>
  <msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[
public string ConvertSex(string sex)
{
if (sex == "F")
return "Female";
else
return "Male";
}


public string TSTime ()
{
DateTime now = DateTime.Now;
string ts = now.ToString("yyyyMMddHHmm");
    return ts;
}



public string MyConcat()
{
DateTime now = DateTime.Now;
string ts = now.ToString("yyyyMMddHHmm");
    return ts;
}



]]></msxsl:script>
</xsl:stylesheet>

Firstly, the error message "XML document must contain a root level element." 首先,错误消息“ XML文档必须包含一个根级元素”。 refers to the output XML, because it is empty! 引用输出 XML,因为它为空!

So, why is it empty? 那么,为什么它是空的? The reason is that your XSL stylesheet templates are selecting non-existent nodes. 原因是您的XSL样式表模板正在选择不存在的节点。 For example, you have: 例如,您有:

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

However, your example code root node is <root/> , so this select will not match it. 但是,示例代码的根节点为<root/> ,因此此选择将不匹配它。

Additionally, the namespaces in your input XML and XSL stylesheet do not match. 此外,您输入的XML和XSL样式表中的名称空间不匹配。 In both the XSL and XML, you need xmlns:s0 to have the same value. 在XSL和XML中,都需要xmlns:s0具有相同的值。

For example, your XSL will produce some output if applied to the following input XML: 例如,如果将XSL应用于以下输入XML,则将产生一些输出:

<?xml version="1.0" encoding="utf-16" ?>
<s0:Root xmlns:s0="http://schemas.microsoft.com/BizTalk/2003/aggschema">
  <PID_PatientIdentification>

  Content

  </PID_PatientIdentification>
</s0:Root>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM