我想在我的XSLT代码中实现Muenchain分组。 [英] I want to implement Muenchain grouping in my XSLT CODE.

查看:75
本文介绍了我想在我的XSLT代码中实现Muenchain分组。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我是这个java脚本和xslt的新手。

< p style ="font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"> 我们使用.js通过调用.js代码中的xslt将.csv文件转换为xml(输出)。

目前我的XSLT创建了很多性能问题,我被告知我必须使用muenchain分组。我用Google搜索但我找不到任何相关的例子.csv有输入文件。请帮忙我的.xslt

 / * JAVA SCRIPT(.JS)获取CSV输入文件并调用XSLT代码和
生成XML输出* /


showAbsolutePath(" InvoiceAdjustment.js");

function showAbsolutePath(path)
{
var fso = new ActiveXObject(" Scripting.FileSystemObject");
var s ="" ;;
s + = fso.GetAbsolutePathName(path);

var foldername = s.substring(0,s.indexOf(path,0) );
showFolderFileList(foldername);
}

函数showFolderFileList(foldername)
{
var fso,f,fc,filename;

fso = new ActiveXObject(" Scripting.FileSystemObject&quo吨);
f = fso.GetFolder(foldername);
fc = new Enumerator(f.files);

for(;!fc.atEnd(); fc.moveNext())
{
filename ="" ;;
filename + = fc.item();

if(filename.slice(-4)==" .csv")
{
convertCSVtoXML(foldername,filename);
}
}

fso = null;
}

函数convertCSVtoXML(foldername,filename)
{
var objDOMDocument = new ActiveXObject(" MSXML2.DOMDocument.4.0");
objDOMDocument.async = false;

//创建标题
objDOMDocument.appendChild(XMLHeader(objDOMDocument));
var objXMLDOMNode =
objDOMDocument.documentElement.selectSingleNode(" // Document");

//声明XML对象 - 这使得作为参数传递更容易
var objXML = new Object();

//从zip文件中打开提取的csv
var fso = new ActiveXObject(" Scripting.FileSystemObject");

var csvFilename = filename;

var tso = fso.OpenTextFile(csvFilename,1);
var strInput;

//循环遍历文件
while(!tso.AtEndOfStream)
{
strInput = tso.ReadLine();

var vInputLine = strInput.split(",");
objXML.a = vInputLine [0];
objXML.b = vInputLine [1];
objXML.c = vInputLine [2];
objXML.d = vInputLine [3];
objXML.e = vInputLine [4];



if(objXML.a!='RebateInvoiceID')
{
objXMLDOMNode.appendChild(XMLFileNode(objDOMDocument,objXML));
}
}
tso.Close();

//加载转换文件
var TransformXSL = new ActiveXObject(" MSXML2.DOMDocument.4.0");
TransformXSL.async = false
TransformXSL.load(foldername +" \\InvAdj.xsl");

//加载XML文件并对其进行转换
var TempStagingDoc = new ActiveXObject(" MSXML2.DOMDocument.4.0");
TempStagingDoc.async = false;
TempStagingDoc.loadXML(objDOMDocument.xml);
var FinalStr = TempStagingDoc.transformNode(TransformXSL);

//只抓取文件名减去任何扩展名
var fn = filename.substring(0,filename.indexOf(" .csv"));
tmpxml = fn +" .xml" ;;

//写出转换后的文件。如果在
之前只写出xml文件转换
// FSObject.WriteLine(objDOMDocument.xml);

var FSObject = fso.CreateTextFile(tmpxml,true);
FSObject.WriteLine(FinalStr);
FSObject.Close();

/ *
//创建空的.flag文件,然后重命名为
tmpxml + =" .flag" ;;
var fsoEmptyFile = fso.CreateTextFile(tmpxml,true);
fsoEmptyFile.Close();

//将.flag文件重命名为.done
var donefilename = tmpxml.substring(0,tmpxml.indexOf(" .flag",0));
donefilename + =" .done" ;;
fso.MoveFile(tmpxml,donefilename);

//删除相应的.csv文件
fso.DeleteFile(csvFilename);

* /


//清除所有对象
objDOMDocument = null;
fso = null;
TransformXSL = null;
objXML = null;
TempStagingDoc = null;
}

函数XMLHeader(objDOMDocument)
{
var XMLHead;
XMLHead = objDOMDocument.createNode(1," Document","");

var objXMLDOMAttribute = objDOMDocument.createAttribute(" Version");
objXMLDOMAttribute.text =" 1.0" ;;
XMLHead.attributes.setNamedItem(objXMLDOMAttribute);

var objXMLDOMAttribute = objDOMDocument.createAttribute(" CreationTimestamp");
objXMLDOMAttribute.text = getTimestamp();
XMLHead.attributes.setNamedItem(objXMLDOMAttribute);

return(XMLHead);
}

函数XMLFileNode(objDOMDocument,objXML)
{
var objXMLDOMNode = objDOMDocument.createNode(1," RawXMLRow","");

objXMLDOMElement = objDOMDocument.createElement(" RebateInvoiceID");
objXMLDOMElement.text = objXML.a;
objXMLDOMNode.appendChild(objXMLDOMElement);

objXMLDOMElement = objDOMDocument.createElement(" RebateEventID");
objXMLDOMElement.text = objXML.b;
objXMLDOMNode.appendChild(objXMLDOMElement);

objXMLDOMElement = objDOMDocument.createElement(" BusinessUnitCode");
函数getBusinessUnitCode(){
var r = String(objXML.c).length;
if(r == 4)
return String(objXML.c);
if(r == 3)
return" 0" + String(objXML.c);
if(r == 2){
return" 00" + String(objXML.c);
}
其他
返回" 000" + String(objXML.c);

}
objXMLDOMElement.text = getBusinessUnitCode();
objXMLDOMNode.appendChild(objXMLDOMElement);

objXMLDOMElement = objDOMDocument.createElement(" CategoryID");
objXMLDOMElement.text = objXML.d;
objXMLDOMNode.appendChild(objXMLDOMElement);

objXMLDOMElement = objDOMDocument.createElement(" PaymentAmount");
objXMLDOMElement.text = objXML.e;
objXMLDOMNode.appendChild(objXMLDOMElement);

return(objXMLDOMNode);
}

函数getTimestamp()
{
var d = new Date();
var mm = padZeros(d.getMonth()+ 1);
var dd = padZeros(d.getDate());
var hh = padZeros(d.getHours());
var mn = padZeros(d.getMinutes());
var ss = padZeros(d.getSeconds());

返回d.getFullYear()+" - " + mm +" - " + dd +" T" + hh +":" + mm +":" ; + ss;
}

函数padZeros(s)
{
if(s< 10)
{
s =" 0" + s;
}
return(s);
}

函数getDate(stringDate)
{
var a = String(stringDate).split(" /");
var strXML;

strDate ="" ;

for(var i = 0; i< a.length; i ++)
{
if(a [i] .length == 1)
strDate + =" 0" + a [i];
else
strDate + = a [i];
}

strDate + ="" ;

返回strDate;
}





/ * XSLT代码* /

<?xml version =" ; 1.0"?>
< xsl:stylesheet xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"版本= QUOT; 1.0"
xmlns:msxsl =" urn:schemas-microsoft-com:xslt"
xmlns:script =" script" exclude-result- prefixes =" msxsl">
< xsl:output omit-xml-declaration =" yes" />

<! - ROOT - >
< xsl:template match =" /">
< EnterpriseDocument>
< xsl:attribute name =" InterfaceName"> RebateInvoiceAdjustmentImport< / xsl:attribute>
< xsl:attribute name =" ClientID">
< xsl:choose>
< xsl:when test =" normalize-space(ClientID)">
< xsl:value-of select =" // Document / RawXMLRow / ClientID" />
< / xsl:when>
< xsl:otherwise> 1000001< / xsl:otherwise>
< / xsl:choose>
< / xsl:attribute>
< xsl:attribute name =" ClientName"> XXXX< / xsl:attribute>
< xsl:attribute name =" Version"> 1.0< / xsl:attribute>
< xsl:attribute name =" CreationSource"> File< / xsl:attribute>
< xsl:attribute name =" CreationTimestamp">
< xsl:value-of select =" script:getTimestamp()" />
< / xsl:attribute>
< xsl:call-template name =" InvAdjData" />
< / EnterpriseDocument>
< / xsl:template>

< xsl:template name =" InvAdjData">
< xsl:for-each select =" // Document / RawXMLRow [not(RebateInvoiceID = preceding-
sibling :: RawXMLRow / RebateInvoiceID)]">
< xsl:sort select =" RebateInvoiceID" />
< RebateInvoice>
< xsl:attribute name =" RebateInvoiceID">
< xsl:value-of select =" RebateInvoiceID" />
< / xsl:attribute>
< xsl:variable name =" InvoiceID">
< xsl:value-of select =" RebateInvoiceID" />
< / xsl:variable>
< xsl:for-each select =" // Document / RawXMLRow [not(RebateEventID = preceding-
sibling :: RawXMLRow [RebateInvoiceID = $ InvoiceID] / RebateEventID)]">
< xsl:if test =" RebateInvoiceID = $ InvoiceID">
< xsl:variable name =" EventID">
< xsl:value-of select =" RebateEventID" />
< / xsl:variable>
< RebateProgram>
< xsl:attribute name =" RebateEventID">
< xsl:value-of select =" RebateEventID" />
< / xsl:attribute>

< xsl:for-each select =" // Document / RawXMLRow [not(BusinessUnitCode = preceding-
sibling :: RawXMLRow [RebateInvoiceID = $ InvoiceID and
RebateEventID = $事件ID] / BusinessUnitCode)]">
< xsl:if test =" RebateInvoiceID = $ InvoiceID和RebateEventID = $ EventID">
< xsl:variable name =" BUCode">
< xsl:value-of select =" BusinessUnitCode" />
< / xsl:variable>
< BusinessUnit>
< xsl:attribute name =" BusinessUnitCode">
< xsl:value-of select =" BusinessUnitCode" />
< / xsl:attribute>

< xsl:for-each select =" // Document / RawXMLRow [not(CategoryID = preceding-
sibling :: RawXMLRow [RebateInvoiceID = $ InvoiceID and RebateEventID = $ EventID
和BusinessUnitCode = $ BUCode] / CategoryID)]">
< xsl:if test =" RebateInvoiceID = $ InvoiceID and RebateEventID = $ EventID
and BusinessUnitCode = $ BUCode">
< ItemCategoryPayment>

< xsl:attribute name =" CategoryID">
< xsl:value-of select =" CategoryID" />
< / xsl:attribute>
< xsl:attribute name =" PaymentAmount">
< xsl:value-of select =" PaymentAmount" />
< / xsl:attribute>
< / ItemCategoryPayment>
< / xsl:if>
< / xsl:for-each>
< / BusinessUnit>
< / xsl:if>

< / xsl:for-each>

< / RebateProgram>
< / xsl:if>
< / xsl:for-each>
< / RebateInvoice>
< / xsl:for-each>

< / xsl:template>

<! - BEGIN JSCRIPT HELPER CODE,保持这个部分尽可能小的
这是一个性能HOG - >
< msxsl:script language =" JScript"实现前缀= QUOT;脚本">
<![CDATA [

函数getTimestamp()
{
var d = new Date();
var m,dy,hr,mn,se;

if(d.getMonth()+ 1< 10)
{
m =" 0" +(d.getMonth()+ 1);
}
else if(d.getMonth()+ 1> 9)
{
m = d.getMonth()+ 1;
}

if(d.getDate()< 10)
{
dy =" 0" +(d.getDate());
}
else if(d.getDate()> 9)
{
dy = d.getDate();
}

if(d.getHours()< 10)
{
hr =" 0" +(d.getHours());
}
else if(d.getHours()> 9)
{
hr = d.getHours();
}

if(d.getMinutes()< 10)
{
mn =" 0" +(d.getMinutes());
}
else if(d.getMinutes()> 9)
{
mn = d.getMinutes();
}

if(d.getSeconds()< 10)
{
se =" 0" +(d.getSeconds());
}
else if(d.getSeconds()> 9)
{
se = d.getSeconds();
}

返回d.getFullYear()+" - " + m +" - " + dy +" T" + hr +":" + mn +":" + se;
}

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

/ *样本.CSV输入数据* /

RebateInvoiceID RebateEventID BusinessUnitCode CategoryID
PaymentAmount
1001667 1002701 4050 1000043 10.26
1001667 1002701 4051 1000043 23.37
1001667 1002702 4074 1000043 12.54
1001667 1002702 4076 1000043 3.99
1001689 1002711 4053 1000043 29.64
1001689 1002711 4054 1000043 2.85
1001689 1002712 4056 1000043 5.7
1001689 1002712 4057 1000043 23.37
1001000 1003701 4062 1000043 5.13
1001000 1003701 4063 1000043 33.06
1001000 1005701 4066 1000043 22.8
1001000 1005701 4070 1000043 10.26

/ * SAMPLE OUT PUT .XML * /

- < EnterpriseDocument InterfaceName =" RebateInvoiceAdjustmentImport"
ClientID =" 1000001" CLIENTNAME = QUOT; XXXX"版本= QUOT; 1.0" CreationSource = QUOT;文件"
CreationTimestamp =" 2012-05-07T13:07:48"的xmlns:脚本= QUOT;脚本">
- < RebateInvoice RebateInvoiceID =" 1001000">
- < RebateProgram RebateEventID =" 1003701">
- < BusinessUnit BusinessUnitCode =" 4062">
< ItemCategoryPayment CategoryID =" 1000043" PaymentAmount = QUOT; 5.13" />
< / BusinessUnit>
- < BusinessUnit BusinessUnitCode =" 4063">
< ItemCategoryPayment CategoryID =" 1000043" PaymentAmount = QUOT; 33.06" />
< / BusinessUnit>
< / RebateProgram>
- < RebateProgram RebateEventID =" 1005701">
- < BusinessUnit BusinessUnitCode =" 4066">
< ItemCategoryPayment CategoryID =" 1000043" PaymentAmount = QUOT; 22.8" />
< / BusinessUnit>
- < BusinessUnit BusinessUnitCode =" 4070">
< ItemCategoryPayment CategoryID =" 1000043" PaymentAmount = QUOT; 10.26" />
< / BusinessUnit>
< / RebateProgram>
< / RebateInvoice>
- < RebateInvoice RebateInvoiceID =" 1001667">
- < RebateProgram RebateEventID =" 1002701">
- < BusinessUnit BusinessUnitCode =" 4050">
< ItemCategoryPayment CategoryID =" 1000043" PaymentAmount = QUOT; 10.26" />
< / BusinessUnit>
- < BusinessUnit BusinessUnitCode =" 4051">
< ItemCategoryPayment CategoryID =" 1000043" PaymentAmount = QUOT; 23.37" />
< / BusinessUnit>
< / RebateProgram>



  &NBSP; &NBSP;  

解决方案


如果您还没有看过它,请检查
这个
的例子。


I'm new to this java script and xslt.

We are using .js which converts the .csv file into xml(output) by calling xslt in .js code.

Currently my XSLT creating a lot of performance issues and i been told that i have to use muenchain grouping. I googled for it but i couldn't find any example related .csv has input file. Please help with my .xslt

/* JAVA SCRIPT (.JS) WHICH TAKES CSV INTPUT FILE AND CALLS XSLT CODE AND  
       GENERATES XML OUTPUT */


        showAbsolutePath("InvoiceAdjustment.js");

       function showAbsolutePath(path)
        {
       var fso = new ActiveXObject("Scripting.FileSystemObject");
       var s = "";
       s += fso.GetAbsolutePathName(path);

       var foldername = s.substring(0,s.indexOf(path,0));
       showFolderFileList(foldername);
        }

        function showFolderFileList(foldername)
        {
         var fso, f, fc, filename;

          fso = new ActiveXObject("Scripting.FileSystemObject");
          f = fso.GetFolder(foldername);
          fc = new Enumerator(f.files);

          for (; !fc.atEnd(); fc.moveNext())
          {
          filename = "";
          filename += fc.item();

          if (filename.slice(-4) == ".csv")
           {
          convertCSVtoXML(foldername, filename);
            }
           }  

         fso = null;
          }

       function  convertCSVtoXML(foldername, filename)
       { 
       var objDOMDocument = new ActiveXObject("MSXML2.DOMDocument.4.0"); 
       objDOMDocument.async = false; 

       //Create Header
        objDOMDocument.appendChild(XMLHeader(objDOMDocument)); 
          var objXMLDOMNode =                                                                                                     
       objDOMDocument.documentElement.selectSingleNode("//Document"); 

      // Declare XML object -- this makes it easier to pass as a parameter 
       var objXML  = new Object(); 

      // Open the extracted csv from zip file
      var fso = new ActiveXObject("Scripting.FileSystemObject");

     var csvFilename = filename;

      var tso = fso.OpenTextFile(csvFilename, 1); 
      var strInput; 

      // Loop through the file 
       while(!tso.AtEndOfStream)  
       { 
       strInput = tso.ReadLine();

      var vInputLine = strInput.split(","); 
     objXML.a = vInputLine[0];
     objXML.b = vInputLine[1];
     objXML.c = vInputLine[2];
     objXML.d = vInputLine[3];
     objXML.e = vInputLine[4];



    if (objXML.a != 'RebateInvoiceID')
     {
     objXMLDOMNode.appendChild(XMLFileNode(objDOMDocument,objXML));
      }    
       } 
        tso.Close();

        // Load Transform file
        var TransformXSL = new ActiveXObject("MSXML2.DOMDocument.4.0");
        TransformXSL.async = false  
        TransformXSL.load(foldername + "\\InvAdj.xsl");

       // Load XML file and transform it
       var TempStagingDoc = new ActiveXObject("MSXML2.DOMDocument.4.0");
       TempStagingDoc.async = false; 
       TempStagingDoc.loadXML(objDOMDocument.xml);      
       var FinalStr = TempStagingDoc.transformNode(TransformXSL);

      // Grab just the file name minus any extension
      var fn = filename.substring(0, filename.indexOf(".csv")); 
       tmpxml = fn + ".xml";  

       // Write out the transformed file. If writing out just the xml file before 
        transform  
      //  FSObject.WriteLine(objDOMDocument.xml);     

      var FSObject = fso.CreateTextFile(tmpxml, true);
        FSObject.WriteLine(FinalStr);
        FSObject.Close();

          /*
      // Create empty .flag file then rename it
      tmpxml += ".flag";
      var fsoEmptyFile = fso.CreateTextFile(tmpxml, true);
         fsoEmptyFile.Close();

      // Rename the .flag file to .done
       var donefilename = tmpxml.substring(0,tmpxml.indexOf(".flag",0));
       donefilename += ".done";
       fso.MoveFile(tmpxml, donefilename);

      // Delete the corresponding .csv file
       fso.DeleteFile(csvFilename);

        */


      // Clear all objects
      objDOMDocument = null; 
       fso = null;
      TransformXSL = null;
       objXML = null;
       TempStagingDoc = null;
           }

        function XMLHeader(objDOMDocument)
         { 
         var XMLHead;
         XMLHead = objDOMDocument.createNode(1, "Document",""); 

         var objXMLDOMAttribute = objDOMDocument.createAttribute("Version"); 
          objXMLDOMAttribute.text = "1.0";
          XMLHead.attributes.setNamedItem(objXMLDOMAttribute);

         var objXMLDOMAttribute = objDOMDocument.createAttribute("CreationTimestamp"); 
         objXMLDOMAttribute.text = getTimestamp();
         XMLHead.attributes.setNamedItem(objXMLDOMAttribute);

          return(XMLHead);
          } 

          function XMLFileNode(objDOMDocument,objXML)
          {     
           var objXMLDOMNode = objDOMDocument.createNode(1, "RawXMLRow","");

          objXMLDOMElement = objDOMDocument.createElement("RebateInvoiceID"); 
          objXMLDOMElement.text = objXML.a;
          objXMLDOMNode.appendChild(objXMLDOMElement);

          objXMLDOMElement = objDOMDocument.createElement("RebateEventID"); 
          objXMLDOMElement.text = objXML.b;
          objXMLDOMNode.appendChild(objXMLDOMElement);

         objXMLDOMElement = objDOMDocument.createElement("BusinessUnitCode");
         function getBusinessUnitCode(){
         var r = String(objXML.c).length;
          if(r == 4)
          return String(objXML.c);
         if( r == 3)
         return "0"+String(objXML.c);
          if(r == 2){
          return "00"+String(objXML.c);
            }
             else
                return "000"+String(objXML.c);

              }
          objXMLDOMElement.text = getBusinessUnitCode();
         objXMLDOMNode.appendChild(objXMLDOMElement);

         objXMLDOMElement = objDOMDocument.createElement("CategoryID"); 
         objXMLDOMElement.text = objXML.d;
         objXMLDOMNode.appendChild(objXMLDOMElement);

        objXMLDOMElement = objDOMDocument.createElement("PaymentAmount"); 
        objXMLDOMElement.text = objXML.e;
        objXMLDOMNode.appendChild(objXMLDOMElement);

          return(objXMLDOMNode);
           }

          function getTimestamp()
            {
          var d = new Date();
          var mm = padZeros(d.getMonth()+1);
          var dd = padZeros(d.getDate());
          var hh = padZeros(d.getHours());
          var mn = padZeros(d.getMinutes());
          var ss = padZeros(d.getSeconds());

          return d.getFullYear()+"-"+ mm +"-"+ dd +"T"+ hh +":"+ mm +":"+ ss;
          }

          function padZeros(s)
          {
           if (s < 10)
              {
            s = "0" + s;
              }
           return(s);
              }

             function getDate(stringDate)
            {
            var a = String(stringDate).split( "/" );
            var strXML ;

            strDate = "" ;

           for ( var i = 0 ; i < a.length; i++ )
           {
            if (a[i].length == 1)
            strDate += "0" + a[i];
            else
            strDate += a[i];
           }

          strDate += "" ;

          return strDate;
           }





             /* XSLT CODE */

   <?xml version="1.0"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"  
                    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
   xmlns:script="script" exclude-result-           prefixes="msxsl">
     <xsl:output omit-xml-declaration="yes"/>

    <!-- ROOT -->
    <xsl:template match="/">
  <EnterpriseDocument>
  <xsl:attribute name="InterfaceName">RebateInvoiceAdjustmentImport</xsl:attribute>
   <xsl:attribute name="ClientID">
    <xsl:choose>
   <xsl:when test="normalize-space(ClientID)">
    <xsl:value-of select="//Document/RawXMLRow/ClientID"/>
   </xsl:when>
  <xsl:otherwise>1000001</xsl:otherwise>
   </xsl:choose>
    </xsl:attribute>
    <xsl:attribute name="ClientName">XXXX</xsl:attribute>
      <xsl:attribute name="Version">1.0</xsl:attribute>
    <xsl:attribute name="CreationSource">File</xsl:attribute>
      <xsl:attribute name="CreationTimestamp">
       <xsl:value-of select="script:getTimestamp()"/>
     </xsl:attribute>
       <xsl:call-template name="InvAdjData"/>
     </EnterpriseDocument>
     </xsl:template>

     <xsl:template name="InvAdjData">
        <xsl:for-each select="//Document/RawXMLRow[not(RebateInvoiceID=preceding- 
         sibling::RawXMLRow/RebateInvoiceID)]">
      <xsl:sort select="RebateInvoiceID"/>
       <RebateInvoice>
       <xsl:attribute name="RebateInvoiceID">
       <xsl:value-of select="RebateInvoiceID"/>
          </xsl:attribute>
            <xsl:variable name="InvoiceID">
     <xsl:value-of select="RebateInvoiceID"/>
         </xsl:variable>
       <xsl:for-each select="//Document/RawXMLRow[not(RebateEventID=preceding-
     sibling::RawXMLRow[RebateInvoiceID=$InvoiceID]/RebateEventID)]">
     <xsl:if test="RebateInvoiceID=$InvoiceID">
       <xsl:variable name="EventID">
        <xsl:value-of select="RebateEventID"/>
      </xsl:variable>
      <RebateProgram>
        <xsl:attribute name="RebateEventID">
          <xsl:value-of select="RebateEventID"/>
        </xsl:attribute>

       <xsl:for-each select="//Document/RawXMLRow[not(BusinessUnitCode=preceding- 
      sibling::RawXMLRow[RebateInvoiceID=$InvoiceID and  
         RebateEventID=$EventID]/BusinessUnitCode)]">
          <xsl:if test="RebateInvoiceID=$InvoiceID and RebateEventID=$EventID">
            <xsl:variable name="BUCode">
              <xsl:value-of select="BusinessUnitCode" />
            </xsl:variable>
            <BusinessUnit>
              <xsl:attribute name="BusinessUnitCode">
              <xsl:value-of select="BusinessUnitCode"/>
            </xsl:attribute>

              <xsl:for-each select="//Document/RawXMLRow[not(CategoryID=preceding-
        sibling::RawXMLRow[RebateInvoiceID=$InvoiceID and RebateEventID=$EventID 
         and BusinessUnitCode=$BUCode]/CategoryID)]">
                <xsl:if test="RebateInvoiceID=$InvoiceID and RebateEventID=$EventID
                 and BusinessUnitCode=$BUCode">
                  <ItemCategoryPayment>

                    <xsl:attribute name="CategoryID">
                      <xsl:value-of select="CategoryID"/>
                    </xsl:attribute>
                    <xsl:attribute name="PaymentAmount">
                      <xsl:value-of select="PaymentAmount"/>
                    </xsl:attribute>
                  </ItemCategoryPayment>
                </xsl:if>
                    </xsl:for-each>
                   </BusinessUnit >
                      </xsl:if>

                 </xsl:for-each>

                </RebateProgram >
               </xsl:if>
              </xsl:for-each>
            </RebateInvoice >
          </xsl:for-each>

          </xsl:template>

            <!-- BEGIN JSCRIPT HELPER CODE, KEEP THIS SECTION AS SMALL AS POSSIBLE  
           IT'S A PERFORMANCE HOG -->
  <msxsl:script language="JScript" implements-prefix="script">
    <![CDATA[

        function getTimestamp()
           {
        var d = new Date();
       var m, dy, hr, mn, se;

     if (d.getMonth()+1 < 10)
   {
   m = "0"+(d.getMonth()+1);
    }
  else if (d.getMonth()+1 > 9)
   {
     m = d.getMonth()+1;
    }

  if (d.getDate() < 10)
     {
   dy = "0"+(d.getDate());
     }
    else if (d.getDate() > 9)
        {
     dy = d.getDate();
     }

   if (d.getHours() < 10)
   {
       hr = "0"+(d.getHours());
      }
      else if (d.getHours() > 9)
      {
         hr = d.getHours();
       }

 if (d.getMinutes() < 10)
   {
   mn = "0"+(d.getMinutes());
     }
    else if (d.getMinutes() > 9)
     {
     mn = d.getMinutes();
      }

     if (d.getSeconds() < 10)
     {
       se = "0"+(d.getSeconds());
      }
  else if (d.getSeconds() > 9)
   {
     se = d.getSeconds();
      }

      return d.getFullYear()+"-"+ m +"-"+ dy +"T"+ hr +":"+ mn +":"+ se;
       }

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

            /* sample .CSV input DATA */

         RebateInvoiceID    RebateEventID   BusinessUnitCode    CategoryID   
         PaymentAmount
         1001667    1002701 4050    1000043 10.26
         1001667    1002701 4051    1000043 23.37
         1001667    1002702 4074    1000043 12.54
         1001667    1002702 4076    1000043 3.99
         1001689    1002711 4053    1000043 29.64
         1001689    1002711 4054    1000043 2.85
         1001689    1002712 4056    1000043 5.7
         1001689    1002712 4057    1000043 23.37
         1001000    1003701 4062    1000043 5.13
         1001000    1003701 4063    1000043 33.06
         1001000    1005701 4066    1000043 22.8
         1001000    1005701 4070    1000043 10.26

        /* PART OF SAMPLE OUT PUT .XML */

       - <EnterpriseDocument InterfaceName="RebateInvoiceAdjustmentImport"      
      ClientID="1000001" ClientName="XXXX" Version="1.0" CreationSource="File" 
      CreationTimestamp="2012-05-07T13:07:48" xmlns:script="script">
       - <RebateInvoice RebateInvoiceID="1001000">
       - <RebateProgram RebateEventID="1003701">
        - <BusinessUnit BusinessUnitCode="4062">
          <ItemCategoryPayment CategoryID="1000043" PaymentAmount="5.13" /> 
           </BusinessUnit>
       - <BusinessUnit BusinessUnitCode="4063">
         <ItemCategoryPayment CategoryID="1000043" PaymentAmount="33.06" /> 
          </BusinessUnit>
          </RebateProgram>
           - <RebateProgram RebateEventID="1005701">
           - <BusinessUnit BusinessUnitCode="4066">
              <ItemCategoryPayment CategoryID="1000043" PaymentAmount="22.8" /> 
            </BusinessUnit>
        - <BusinessUnit BusinessUnitCode="4070">
        <ItemCategoryPayment CategoryID="1000043" PaymentAmount="10.26" /> 
        </BusinessUnit>
         </RebateProgram>
          </RebateInvoice>
       - <RebateInvoice RebateInvoiceID="1001667">
       - <RebateProgram RebateEventID="1002701">
       - <BusinessUnit BusinessUnitCode="4050">
        <ItemCategoryPayment CategoryID="1000043" PaymentAmount="10.26" /> 
       </BusinessUnit>
      - <BusinessUnit BusinessUnitCode="4051">
        <ItemCategoryPayment CategoryID="1000043" PaymentAmount="23.37" /> 
        </BusinessUnit>
          </RebateProgram>




       

解决方案

Hi,

If you haven't already seen it, check this for an example.


这篇关于我想在我的XSLT代码中实现Muenchain分组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆