none
Compiling JScript/CSharp scripts is not supported XSLCompiledTransform error RRS feed

  • Question

  • Can someone please help.

    I keep getting XSLT compile error, and Inner Exception Compiling JScript/CSharp scripts is not supported.

    XML FILE:

    <?xml version="1.0" encoding="utf-8"?>
    <Document>
    <ECOHeader>
    <senderID>1</senderID>
    <receiverID>1</receiverID>
    <transactionSet>1</transactionSet>
    <transactionID>1</transactionID>
    </ECOHeader>
    <SenderIdentification>
    <senderID>1</senderID>
    </SenderIdentification>
    <ReceiverIdentification>
    <receiverID>1</receiverID>
    </ReceiverIdentification>
    <ControlNumber>
    <number>1</number>
    </ControlNumber>
    <DocumentTag>
    <version>1</version>
    </DocumentTag>
    <Consignment>
    <ConsignmentDetail>1</ConsignmentDetail>
    <QuantityDetail>1</QuantityDetail>
    </Consignment>
    <StatusDetailsLoop>
    <BKD>
    <MovementDetail>1</MovementDetail>
    <DateTime>1</DateTime>
    <Airport>1</Airport>
    <QuantityDetail>1</QuantityDetail>
    <TimeOfDepartureInformation>1</TimeOfDepartureInformation>
    <TimeOfArrivalInformation>1</TimeOfArrivalInformation>
    </BKD>
    </StatusDetailsLoop>
    </Document>

    XSL FILE:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="mynamespace" exclude-result-prefixes="msxsl user">
      <xsl:output encoding="iso-8859-1" indent="yes" />
      <xsl:template match="Document">
        <xsl:variable name="AirWayBillNumber" select="string(./Consignment/ConsignmentDetail)" />
        <xsl:variable name="AirportCode" select="string(user:GetAirportCode($AirWayBillNumber,number('6')))" />
        <Document>
          <ECOHeader>
            <senderID>
              <xsl:value-of select="./ECOHeader/senderID" />
            </senderID>
            <receiverID>
              <xsl:value-of select="./ECOHeader/receiverID" />
            </receiverID>
            <transactionSet>
              <xsl:call-template name="GetAirTtrackerCustomerDocumentType">
                <xsl:with-param name="id" select="./ECOHeader/receiverID" />
              </xsl:call-template>
            </transactionSet>
            <referenceNo>
              <xsl:value-of select="user:GetReferenceNumber($AirWayBillNumber,6)" />
            </referenceNo>
            <transactionID />
            <senderLocale>
              <xsl:value-of select="./Header/senderLocale" />
            </senderLocale>
            <receiverLocale>
              <xsl:value-of select="./ECOHeader/receiverLocale" />
            </receiverLocale>
          </ECOHeader>
          <Header>
             <xsl:variable name="hdrQtyDetail" select="./Consignment/QuantityDetail" />
            <Consignment>
              <AirportPrefix>
                <xsl:value-of select="substring-before(./Consignment/ConsignmentDetail,'-')" />
              </AirportPrefix>
              <AWBIdentification>
                <xsl:value-of select="user:GetReferenceNumber($AirWayBillNumber,6)" />
              </AWBIdentification>
              <AirportOrigin>
                <xsl:value-of select="substring($AirportCode,1,string-length($AirportCode)-3)" />
              </AirportOrigin>
              <AirportDestination>
                <xsl:value-of select="substring($AirportCode,4,string-length($AirportCode)-3)" />
              </AirportDestination>
              <QtyShipmentDescriptionCode>
                <xsl:value-of select="substring($hdrQtyDetail,0,2)" />
              </QtyShipmentDescriptionCode>
              <QtyDetailNoOfPieces>
                <xsl:call-template name="GetQtyData">
                  <xsl:with-param name="node" select="$hdrQtyDetail" />
                  <xsl:with-param name="trimChar" select="substring-after($hdrQtyDetail,'T')" />
                  <xsl:with-param name="trim2Char" select="substring-after($hdrQtyDetail,'P')" />
                </xsl:call-template>
              </QtyDetailNoOfPieces>
              <xsl:call-template name="GetQtyWeightData">
                <xsl:with-param name="node" select="$hdrQtyDetail" />
                <xsl:with-param name="trimChar" select="substring-after($hdrQtyDetail,'K')" />
                <xsl:with-param name="trimChar2" select="substring-after($hdrQtyDetail,'L')" />
              </xsl:call-template>
            </Consignment>
            <FlightIdentification>
              <xsl:call-template name="GetCarrierAndFlightNumber">
                <xsl:with-param name="node" select="./MovementDetail"></xsl:with-param>
              </xsl:call-template>
            </FlightIdentification>
            <genericContent>
              <ATTransactionId />
              <ShipperName>
                <xsl:if test="local-name()='RCS' or local-name()='FOH'">
                  <xsl:value-of select="./ReceiveFromDetail" />
                </xsl:if>
              </ShipperName>
              <TotalNoOfPieces>
                 <xsl:call-template name="GetQtyData">
                  <xsl:with-param name="node" select="$hdrQtyDetail" />
                  <xsl:with-param name="trimChar" select="substring-after($hdrQtyDetail,'T')" />
                </xsl:call-template>
              </TotalNoOfPieces>
            </genericContent>
          </Header>
          <Detail>
            <xsl:for-each select="./StatusDetailsLoop">
              <xsl:call-template name="GetAllStatusDetails">
                <xsl:with-param name="node" select="RCS|RCT|RCF|BKD|MAN|DEP|PRE|TRM|TFD|NFD|AWD|CCD|DLV|DIS|CRC|DDL|TGC|ARR|AWR|FOH" />
              </xsl:call-template>
            </xsl:for-each>
          </Detail>
          <Summary>
            <xsl:for-each select="./Customs">
              <Customs>
                <xsl:copy-of select="*" />
              </Customs>
            </xsl:for-each>
            <xsl:for-each select="./UnitLoadDevice">
              <UnitLoadDevice>
                <xsl:copy-of select="*" />
              </UnitLoadDevice>
            </xsl:for-each>
            <xsl:for-each select="./OtherServiceInformation">
              <OtherServiceInformation>
                <xsl:copy-of select="*" />
              </OtherServiceInformation>
            </xsl:for-each>
          </Summary>
        </Document>
      </xsl:template>
      <!-- Start of Utility Templates-->
      <xsl:template name="GetAirTtrackerCustomerDocumentType">
        <xsl:param name="id" />
        <xsl:choose>
          <!-- If there is a new customer that will use AirTracker, 
    please add the document type here-->
          <xsl:when test="$id = '1'">1</xsl:when>
        </xsl:choose>
      </xsl:template>
      <xsl:template name="GetAllStatusDetails">
        <xsl:param name="node" />
        <xsl:for-each select="$node">     
          <!-- Variable Declarion -->
              <xsl:variable name="linQtyDetail" select="./QuantityDetail" />
              <xsl:variable name="linAirport" select="./Airport" />
              <xsl:variable name="strDate" select="./DateTime"></xsl:variable>
              <xsl:variable name="depTime" select="./TimeOfDepartureInformation"></xsl:variable>
              <xsl:variable name="arrTime" select="./TimeOfArrivalInformation"></xsl:variable>
              <!-- End of Variable Declaration -->
          <StatusDetails>
            <StatusCode>
              <xsl:value-of select="local-name()" />
            </StatusCode>
            <xsl:copy-of select="*" />
            <genericContent>
              <StatusDescription />
              <DateTime>
                <xsl:call-template name="FormatDate">
                  <xsl:with-param name="yyyy" select="user:getDate()"></xsl:with-param>
                  <xsl:with-param name="mmm" select="substring($strDate,3,3)"></xsl:with-param>
                  <xsl:with-param name="dd" select="substring($strDate,1,2)"></xsl:with-param>
                  <xsl:with-param name="actualTime" select="substring($strDate,6,4)"></xsl:with-param>
                  <xsl:with-param name="actualTime2" select="$depTime"></xsl:with-param>
                </xsl:call-template>
              </DateTime>
              <DateTimeDescription>
                <xsl:call-template name="GetDateDescription">
                  <xsl:with-param name="node" select="local-name()"></xsl:with-param>
                </xsl:call-template>
              </DateTimeDescription>
              <QtyShipmentDescriptionCode>
                <xsl:value-of select="substring(./QuantityDetail,0,2)" />
              </QtyShipmentDescriptionCode>
              <QtyDetailNoOfPieces>
                <xsl:call-template name="GetQtyData">
                  <xsl:with-param name="node" select="$linQtyDetail" />
                  <xsl:with-param name="trimChar" select="substring-after($linQtyDetail,'T')" />
                  <xsl:with-param name="trim2Char" select="substring-after($linQtyDetail,'P')" />
                </xsl:call-template>
              </QtyDetailNoOfPieces>
              <xsl:call-template name="GetQtyWeightData">
                <xsl:with-param name="node" select="$linQtyDetail" />
                <xsl:with-param name="trimChar" select="substring-after($linQtyDetail,'K')" />
                <xsl:with-param name="trimChar2" select="substring-after($linQtyDetail,'L')" />
              </xsl:call-template>
              <xsl:call-template name="GetCarrierAndFlightNumber">
                <xsl:with-param name="node" select="./MovementDetail"></xsl:with-param>
              </xsl:call-template>
              <AirportCodeDeparture>
                <xsl:value-of select="substring($linAirport,1,string-length($linAirport)-3)" />
              </AirportCodeDeparture>
              <AirportCodeArrival>
                <xsl:value-of select="substring($linAirport,4,string-length($linAirport)-3)" />
              </AirportCodeArrival>
              <ReceivedFromDetail>
                <xsl:value-of select="./ReceiveFromDetail" />
              </ReceivedFromDetail>
              <DateTimeOfDeparture>
                <xsl:if test="string-length($depTime) &gt; 0">
                <xsl:call-template name="FormatDate">
                  <xsl:with-param name="yyyy" select="user:getDate()"></xsl:with-param>
                  <xsl:with-param name="mmm" select="substring($strDate,3,3)"></xsl:with-param>
                  <xsl:with-param name="dd" select="substring($strDate,1,2)"></xsl:with-param>
                  <xsl:with-param name="actualTime" select="substring($strDate,6,4)"></xsl:with-param>
                  <xsl:with-param name="actualTime2" select="$depTime"></xsl:with-param>
                </xsl:call-template>
               </xsl:if>
              </DateTimeOfDeparture>
              <DateTimeOfArrival>
                <xsl:choose>
    <xsl:when test="string-length($arrTime) &gt; 0">
      <xsl:call-template name="FormatDate">
    <xsl:with-param name="yyyy" select="user:getDate()"></xsl:with-param>
    <xsl:with-param name="mmm" select="substring($strDate,3,3)"></xsl:with-param>
    <xsl:with-param name="dd" select="substring($strDate,1,2)"></xsl:with-param>
    <xsl:with-param name="actualTime" select="substring($strDate,6,4)"></xsl:with-param>
    <xsl:with-param name="actualTime2" select="$arrTime"></xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:call-template name="FormatDate">
    <xsl:with-param name="yyyy" select="user:getDate()"></xsl:with-param>
    <xsl:with-param name="mmm" select="substring($strDate,3,3)"></xsl:with-param>
    <xsl:with-param name="dd" select="substring($strDate,1,2)"></xsl:with-param>
    <xsl:with-param name="actualTime" select="substring($strDate,6,4)"></xsl:with-param>
      </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
              </DateTimeOfArrival>
              <VolumeDetail>
                <xsl:value-of select="./VolumeDetail" />
              </VolumeDetail>
              <DensityGroup>
                <xsl:value-of select="./DensityGroup" />
              </DensityGroup>
              <NotificationOrDeliveryDetail>
                <xsl:value-of select="./NotificationOrDeliveryDetail" />
              </NotificationOrDeliveryDetail>
              <TransferReference>
                <xsl:value-of select="./TransferReference" />
              </TransferReference>
              <TransferredDetail>
                <xsl:value-of select="./TransferredDetail" />
              </TransferredDetail>
            </genericContent>
          </StatusDetails>
        </xsl:for-each>
      </xsl:template>
      <xsl:template name="FormatDate">
        <xsl:param name="date" />
        <xsl:param name="yyyy" />
        <xsl:param name="mmm" />
        <xsl:param name="dd" />
        <xsl:param name="actualTime" />
        <xsl:param name="actualTime2" />
        <xsl:variable name="cMonth">
          <xsl:choose>
            <xsl:when test="$mmm = 'JAN'">01</xsl:when>
            <xsl:when test="$mmm = 'FEB'">02</xsl:when>
            <xsl:when test="$mmm = 'MAR'">03</xsl:when>
            <xsl:when test="$mmm = 'APR'">04</xsl:when>
            <xsl:when test="$mmm = 'MAY'">05</xsl:when>
            <xsl:when test="$mmm = 'JUN'">06</xsl:when>
            <xsl:when test="$mmm = 'JUL'">07</xsl:when>
            <xsl:when test="$mmm = 'AUG'">08</xsl:when>
            <xsl:when test="$mmm = 'SEP'">09</xsl:when>
            <xsl:when test="$mmm = 'OCT'">10</xsl:when>
            <xsl:when test="$mmm = 'NOV'">11</xsl:when>
            <xsl:when test="$mmm = 'DEC'">12</xsl:when>
          </xsl:choose>
        </xsl:variable>
        <!--
          Actual Time A, Estimated Time E, Scheduled Time S -->
        <xsl:variable name="arrOrDepTime">
           <xsl:choose>
              <xsl:when test="contains($actualTime2,'A')">
            <xsl:value-of select="substring-after($actualTime2,'A')" />
          </xsl:when>
          <xsl:when test="contains($actualTime2,'S')">
            <xsl:value-of select="substring-after($actualTime2,'S')" />
          </xsl:when>
            <xsl:when test="contains($actualTime2,'E')">
            <xsl:value-of select="substring-after($actualTime2,'E')" />
          </xsl:when>
          </xsl:choose>
        </xsl:variable>
        <xsl:choose>
          <xsl:when test="string-length($actualTime) &gt; 0">
            <xsl:value-of select=" concat ($yyyy,'-',$cMonth,'-',$dd,'T',$actualTime) " />
          </xsl:when>
          <xsl:when test="string-length($arrOrDepTime) &gt; 0">
            <xsl:value-of select=" concat ($yyyy,'-',$cMonth,'-',$dd,'T',$arrOrDepTime)" />
          </xsl:when>
          <xsl:when test="string-length($arrOrDepTime) &gt; 0">
            <xsl:value-of select=" concat ($yyyy,'-',$cMonth,'-',$dd,'T',$arrOrDepTime) " />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select=" concat ($yyyy,'-',$cMonth,'-',$dd,'T','000000') " />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
      <xsl:template name="GetQtyData">
        <xsl:param name="node" />
        <xsl:param name="trimChar" />
        <xsl:param name="trim2Char" />
        <xsl:choose>
          <xsl:when test="contains($trim2Char,'K')">
            <xsl:value-of select="substring-before($trim2Char,'K')" />
          </xsl:when>
          <xsl:when test="contains($trim2Char,'L')">
            <xsl:value-of select="substring-before($trim2Char,'L')" />
          </xsl:when>
          <xsl:when test="contains($trimChar,'L')">
            <xsl:value-of select="substring-before($trimChar,'L')" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="substring-before($trimChar,'K')" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
      <xsl:template name="GetCarrierAndFlightNumber">
        <xsl:param name="node"></xsl:param>
        <Carrier>
          <xsl:value-of select="substring($node,1,string-length($node)-3)" />
        </Carrier>
        <FlightNumber>
          <xsl:value-of select="substring($node,3,string-length($node)-2)" />
        </FlightNumber>
      </xsl:template>
      <xsl:template name="GetQtyWeightData">
        <xsl:param name="node" />
        <xsl:param name="trimChar" />
        <xsl:param name="trim2Char" />
        <xsl:choose>
          <xsl:when test="contains($node,'L')">
            <QtyDetailWeightCode>
              <xsl:value-of select="substring($node,string-length(substring-before($node,'L'))+1,1)" />
            </QtyDetailWeightCode>
            <QtyDetailWeight>
              <xsl:value-of select="substring-after($node,'L')" />
            </QtyDetailWeight>
          </xsl:when>
          <xsl:otherwise>
            <QtyDetailWeightCode>
              <xsl:value-of select="substring($node,string-length(substring-before($node,'K'))+1,1)" />
            </QtyDetailWeightCode>
            <QtyDetailWeight>
              <xsl:value-of select="substring-after($node,'K')" />
            </QtyDetailWeight>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
      <xsl:template name="GetDateDescription">
        <xsl:param name="node"></xsl:param>
        <xsl:variable name="cNodeName">
          <xsl:choose>
            <xsl:when test="$node = 'RCS'">Receipt</xsl:when>
            <xsl:when test="$node = 'RCT'">Transfer Carrier</xsl:when>
            <xsl:when test="$node = 'RCF'">Scheduled Arrival</xsl:when>
            <xsl:when test="$node = 'BKD'">Booked</xsl:when>
            <xsl:when test="$node = 'MAN'">Manifest</xsl:when>
            <xsl:when test="$node = 'DEP'">Scheduled Departure</xsl:when>
            <xsl:when test="$node = 'PRE'">Prepared for Loading</xsl:when>
            <xsl:when test="$node = 'TRM'"></xsl:when>
            <xsl:when test="$node = 'TFD'">Transfer</xsl:when>
            <xsl:when test="$node = 'NFD'">Notification</xsl:when>
            <xsl:when test="$node = 'AWD'">Delivery</xsl:when>
            <xsl:when test="$node = 'CCD'">Clearance</xsl:when>
            <xsl:when test="$node = 'DLV'">Delivery</xsl:when>
            <xsl:when test="$node = 'DIS'">Discrepancy</xsl:when>
            <xsl:when test="$node = 'CRC'">Reporting</xsl:when>
            <xsl:when test="$node = 'DDL'">Delivery to consignee's door</xsl:when>
            <xsl:when test="$node = 'TGC'">Transfer</xsl:when>
            <xsl:when test="$node = 'ARR'">Scheduled Arrival</xsl:when>
            <xsl:when test="$node = 'AWR'">Scheduled Arrival</xsl:when>
            <xsl:when test="$node = 'FOH'">Receipt</xsl:when>
          </xsl:choose>
        </xsl:variable>
        <xsl:value-of select="$cNodeName" />
      </xsl:template>
      <msxsl:script language="VBScript" implements-prefix="user">
      <![CDATA[

    Function GetAirportCode(ByVal str, Byval noOfchar)
    Dim strOrig
        Dim iNum
        
        strOrig = Cstr(str)
        iNum = CInt(noOfchar)
     
    GetAirportCode = Right(strOrig, iNum)

    End Function

    Function GetReferenceNumber(ByVal str, Byval noOfchar)

    Dim strOrig
    Dim strlength
        Dim iNum

    strOrig = Cstr(str)
        iNum = CInt(noOfchar)
    strLength = Len(strOrig)

    GetReferenceNumber = Left(strOrig, strLength - iNum)

    End Function

      Function getDate() 

       strMonth = Month(now) 
       strDay = Day(now)
       intDay = len(Day(now))
       intMonth = len(Month(now))
     
       If intDay = 1 then

         strDay = "0" & Day(now)

       End If
     
       If intMonth = 1 then

         strMonth = "0" & Month(now)

       End If
       
       getDate = Year(now) 
    End Function 

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

    Monday, October 14, 2019 7:17 AM

All replies

  • Check if your code is similar to documented sample: https://docs.microsoft.com/en-us/dotnet/standard/data/xml/xslt-stylesheet-scripting-using-msxsl-script.

    Show details about your program that perform the transformation.

    Probably some of the scripts can be re-implemented using available XSLT functions.

    Monday, October 14, 2019 8:28 AM
  • Hi,

    I just implement it like below:

            XslTransform transformer = new XslTransform();
            transformer.Load(xslPath);

    OTHER APPROACH:

            XslCompiledTransform transformer = new XslCompiledTransform();
            var settings = new XsltSettings();
            settings.EnableScript = true;
            transformer.Load(xslPath, settings, new XmlUrlResolver());

    same with compile error



    • Edited by Dev Jo B Monday, October 14, 2019 12:05 PM
    Monday, October 14, 2019 11:31 AM
  • Hi Dev Jo B,

    I modified your source XML slightly to accommodate the following function call:

    user:GetReferenceNumber($AirWayBillNumber,6)

    <ConsignmentDetail>123456789</ConsignmentDetail>

    and everything worked with the c# below:

    void Main()
    {
    	const string SOURCEXMLFILE = @"e:\Temp\XSLT_VBScript\Input.xml";
    	const string XSLTFILE = @"e:\Temp\XSLT_VBScript\VB.NET.xslt";
    	const string OUTPUTXMLFILE = @"e:\temp\XSLT_VBScript\output.xml";
    	bool paramXSLT = true;
    
    	try
    	{
    		XsltArgumentList xslArg = new XsltArgumentList();
    
    		using (XmlReader src = XmlReader.Create(SOURCEXMLFILE))
    		{
    			XslCompiledTransform xslt = new XslCompiledTransform();
    			xslt.Load(XSLTFILE, new XsltSettings(true, true), new XmlUrlResolver());
    
    			XmlWriterSettings settings = xslt.OutputSettings.Clone();
    			settings.IndentChars = "\t";
    			// to remove BOM
    			settings.Encoding = new UTF8Encoding(false);
    
    			using (XmlWriter result = XmlWriter.Create(OUTPUTXMLFILE, settings))
    			{
    				xslt.Transform(src, xslArg, result, new XmlUrlResolver());
    				result.Close();
    			}
    		}
    		Console.WriteLine("File '{0}' has been generated.", OUTPUTXMLFILE);
    	}
    	catch (Exception ex)
    	{
    		Console.WriteLine(ex.Message);
    	}
    }



    Wednesday, October 16, 2019 3:24 PM