Biztalk下使用XSLT进行XML转换

Biztalk下使用XSLT进行XML转换,xml,xslt,biztalk,Xml,Xslt,Biztalk,我需要使用XSLT在Biztalk下进行XML转换,但问题是我对它不熟悉,并且很难理解它 我需要的是一个可以转换此源XML的XSLT脚本: <?xml version="1.0"?> <ns0:usp_GetStudentListResponse xmlns:ns0="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/BizTalk"> <ns0:StoredProcedureResultSet0

我需要使用XSLT在Biztalk下进行XML转换,但问题是我对它不熟悉,并且很难理解它

我需要的是一个可以转换此源XML的XSLT脚本:

<?xml version="1.0"?>
<ns0:usp_GetStudentListResponse xmlns:ns0="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/BizTalk">
   <ns0:StoredProcedureResultSet0>
      <ns1:StoredProcedureResultSet0 xmlns:ns1="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_GetStudentList">
         <ns1:Subject>Math</ns1:Subject> 
         <ns1:TestDate>2016-11-13T00:00:00.000-00:00</ns1:TestDate> 
         <ns1:SectionId>1</ns1:SectionId> 
         <ns1:SectionName>Red</ns1:SectionName> 
         <ns1:StudentName>John Doe</ns1:StudentName> 
      </ns1:StoredProcedureResultSet0>
      <ns1:StoredProcedureResultSet0 xmlns:ns1="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_GetStudentList">
         <ns1:Subject>Math</ns1:Subject> 
         <ns1:TestDate>2016-11-13T00:00:00.000-00:00</ns1:TestDate> 
         <ns1:SectionId>1</ns1:SectionId> 
         <ns1:SectionName>Red</ns1:SectionName> 
         <ns1:StudentName>Jane Doe</ns1:StudentName> 
      </ns1:StoredProcedureResultSet0>
      <ns1:StoredProcedureResultSet0 xmlns:ns1="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_GetStudentList">
         <ns1:Subject>Math</ns1:Subject> 
         <ns1:TestDate>2016-11-13T00:00:00.000-00:00</ns1:TestDate> 
         <ns1:SectionId>1</ns1:SectionId> 
         <ns1:SectionName>Red</ns1:SectionName> 
         <ns1:StudentName>Lee Copper</ns1:StudentName> 
      </ns1:StoredProcedureResultSet0>

      <ns1:StoredProcedureResultSet0 xmlns:ns1="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_GetStudentList">
         <ns1:Subject>Math</ns1:Subject> 
         <ns1:TestDate>2016-11-12T00:00:00.000-00:00</ns1:TestDate> 
         <ns1:SectionId>2</ns1:SectionId> 
         <ns1:SectionName>Blue</ns1:SectionName> 
         <ns1:StudentName>Mary Steel</ns1:StudentName> 
      </ns1:StoredProcedureResultSet0>
      <ns1:StoredProcedureResultSet0 xmlns:ns1="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_GetStudentList">
         <ns1:Subject>Math</ns1:Subject> 
         <ns1:TestDate>2016-11-12T00:00:00.000-00:00</ns1:TestDate> 
         <ns1:SectionId>2</ns1:SectionId> 
         <ns1:SectionName>Blue</ns1:SectionName> 
         <ns1:StudentName>Steve Burry</ns1:StudentName> 
      </ns1:StoredProcedureResultSet0>
   </ns0:StoredProcedureResultSet0>
   <ns0:ReturnValue>5</ns0:ReturnValue>
</ns0:usp_GetStudentListResponse>

数学
2016-11-13T00:00:00.000-00:00
1.
红色
无名氏
数学
2016-11-13T00:00:00.000-00:00
1.
红色
无名氏
数学
2016-11-13T00:00:00.000-00:00
1.
红色
李铜
数学
2016-11-12T00:00:00.000-00:00
2.
蓝色
玛丽·斯蒂尔
数学
2016-11-12T00:00:00.000-00:00
2.
蓝色
史蒂夫·伯里
5.
要输出此XML,请执行以下操作:

<ns0:StudentListSumEnv xmlns:ns0="http://School.Subject.Schema.StudentListSumEnv">  
   <ns1:StudentListSumData xmlns:ns1="http://School.Subject.Schema.StudentListSumData">
      <ns1:Subject>Math</ns1:Subject> 
      <ns1:TestDate>2016-11-13T00:00:00.000-00:00</ns1:TestDate> 
      <ns1:SectionId>1</ns1:SectionId> 
      <ns1:SectionName>Red</ns1:SectionName> 
      <ns1:TotalStudent>3</ns1:TotalStudent> 
   </ns1:StudentListSumData>
   <ns1:StudentListSumData xmlns:ns1="http://School.Subject.Schema.StudentListSumData">
      <ns1:Subject>Math</ns1:Subject> 
      <ns1:TestDate>2016-11-12T00:00:00.000-00:00</ns1:TestDate> 
      <ns1:SectionId>2</ns1:SectionId> 
      <ns1:SectionName>Blue</ns1:SectionName> 
      <ns1:TotalStudent>2</ns1:TotalStudent> 
   </ns1:StudentListSumData>
</ns0:StudentListSumEnv>

数学
2016-11-13T00:00:00.000-00:00
1.
红色
3.
数学
2016-11-12T00:00:00.000-00:00
2.
蓝色
2.
条件是:

  • 应按ns1:Subject和ns1:TestDate以及ns1:SectionId分组
  • 应统计上述组下的学生总数(ns1:Subject和ns1:TestDate和ns1:SectionId)

对不起,伙计们,在翻阅我的剧本两个小时后,我终于解决了我的问题

下面是我的XSLT代码:

<?xml version="1.0"?>
 <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 s2 s1" version="1.0" 
    xmlns:s1="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_GetStudentList" 
    xmlns:s2="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/BizTalk" 
    xmlns:s0="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_DedOt_GetOffSignerCrewList">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="GroupByBatchCode" match="s2:usp_GetStudentListResponse/s2:StoredProcedureResultSet0/s1:StoredProcedureResultSet0" use="concat(s1:Subject, '-', s1:TestDate, '-', s1:SectionId)"/>

<xsl:template match="/">
   <StudentListSumEnv xmlns:ns0="http://School.Subject.Schema.StudentListSumEnv">
      <xsl:for-each select="s2:usp_GetStudentListResponse/s2:StoredProcedureResultSet0/s1:StoredProcedureResultSet0[generate-id(.)=generate-id(key('GroupByBatchCode',concat(s1:Subject, '-', s1:TestDate, '-', s1:SectionId)))]">
         <StudentListSumData xmlns:ns1="http://School.Subject.Schema.StudentListSumData">   
            <Subject>
               <xsl:value-of select="s1:Subject/text()" />
            </Subject>
            <TestDate>
               <xsl:value-of select="s1:TestDate/text()" />
            </TestDate>
            <SectionId>
               <xsl:value-of select="s1:SectionId/text()" />
            </SectionId>
            <SectionName>
               <xsl:value-of select="s1:SectionName/text()" />
            </SectionName>

            <TotalCount>
              <xsl:variable name="batchCodes" select="key('GroupByBatchCode',concat(s1:Subject, '-', s1:TestDate, '-', s1:SectionId))"/>
              <xsl:value-of select="count($batchCodes)"/>
            </TotalCount>

         </StudentListSumData>    
      </xsl:for-each> 
   </StudentListSumEnv>
</xsl:template>
</xsl:stylesheet>

结果如下:

<?xml version="1.0" encoding="UTF-8"?>
<StudentListSumEnv xmlns:ns0="http://School.Subject.Schema.StudentListSumEnv">
    <StudentListSumData xmlns:ns1="http://School.Subject.Schema.StudentListSumData">
        <Subject>Math</Subject>
        <TestDate>2016-11-13T00:00:00.000-00:00</TestDate>
        <SectionId>1</SectionId>
        <SectionName>Red</SectionName>
        <TotalCount>3</TotalCount>
    </StudentListSumData>
    <StudentListSumData xmlns:ns1="http://School.Subject.Schema.StudentListSumData">
        <Subject>Math</Subject>
        <TestDate>2016-11-12T00:00:00.000-00:00</TestDate>
        <SectionId>2</SectionId>
        <SectionName>Blue</SectionName>
        <TotalCount>2</TotalCount>
    </StudentListSumData>
</StudentListSumEnv>

数学
2016-11-13T00:00:00.000-00:00
1.
红色
3.
数学
2016-11-12T00:00:00.000-00:00
2.
蓝色
2.
感谢作为我的脚本编辑器的出色的在线xslt站点


这里是我的完整脚本=>

欢迎来到SO:-)到目前为止,您尝试了什么?我们不是一个代码编写服务,而是帮助您编写代码,但为此,您必须编辑您的问题,以实际显示到目前为止您所获得的xsl。通过一个简单的Google dig,您在包含XSLT解释时也会遇到类似的问题。