Carthax
Carthax

Reputation: 119

C# in xslt -- Cannot find a matching 1-argument function named {urn:my-scripts}ConvertUTCtoLocal()

I am not using Saxon; I am using straight XSLT 1.0.
I am using the following XSLT document:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:a="http://schemas.datacontract.org/2004/07/Delek.Store"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="urn:my-scripts">

  <msxsl:script implements-prefix='user' language='CSharp'>
    <![CDATA[  
    
      public string ConvertUTCtoLocal(DateTime EndTime)
      {
        var Local = EndTime.ToLocalTime().ToString("MM/dd/yyyy") + " " + EndTime.ToLocalTime().ToString("HH:mm:ss");
        return Local;
      }
    
    ]]>
  </msxsl:script>

  <!-- .. since we have a source default namespace we have to declare a namespace here   exclude-result-prefixes="msxsl" -->
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="header" />
  <xsl:param name="footer"/>
  <xsl:param name="ReceiptLayoutCodeType"/>
  <xsl:variable name="spaces27" select="'                           '"/>
  <xsl:template match="/">
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Body>
        <epos-print xmlns="http://www.epson-pos.com/schemas/2011/03/epos-print">
          <xsl:apply-templates select ="Sale"/>
          <feed unit="24"/>
          <cut/>
        </epos-print>
      </s:Body>
    </s:Envelope>
  </xsl:template>
  <xsl:template match="Sale">
    <text lang="en" smooth="true" align="left" >
      Date<xsl:value-of select="concat(substring($spaces27,9),user:ConvertUTCtoLocal(EndTime))"/>
    </text>

  </xsl:template>

</xsl:stylesheet>

When it tries to call the C# script, I get the error

Cannot find a matching 1-argument function named {urn:my-scripts}ConvertUTCtoLocal()

Every search I've done returns errors with Saxon code. I'm not using Saxon code, and everything I read says the formatting is different than that used in standard W3C XSLT.

Does anyone have any advice on how to get this code to work?

The really odd bit is that I am checking with https://www.freeformatter.com/xsl-transformer.html, and it is saying the same thing for any example code I'm using from the web.

So is it my code? Is it something going on with an update to XML 1.0?

I'm currently lost, and could use some assistance getting out of the weeds.

XML data with which people can test:

<Sale z:Id="i1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
  <AllItems>
   <!--Data Removed-->
  </AllItems>
  <CreditTendered>-8.17</CreditTendered>
  <EndTime>2018-10-22T15:25:35.0562305Z</EndTime>
  <GrossFuelSaleAmount>0</GrossFuelSaleAmount>
  <GrossNonFuelSaleAmount>7.48</GrossNonFuelSaleAmount>
  <IdPerson>1000</IdPerson>
  <IdRowStateCode>0</IdRowStateCode>
  <IdSale>8</IdSale>
  <IdSite>1</IdSite>
  <IdWorkflowStateCode>Completed</IdWorkflowStateCode>
  <IsTaxExempt>false</IsTaxExempt>
  <Loyalties />
  <NetNonFuelSaleAmount>7.48</NetNonFuelSaleAmount>
  <PaymentMethods>
    <!--Data Removed-->
  </PaymentMethods>
  <Receipts>
    <SaleReceipt z:Id="i15">
      <IdReceiptTypeCode>Store</IdReceiptTypeCode>
      <IdRowStateCode>0</IdRowStateCode>
      <IdSale>8</IdSale>
      <IdSaleReceipt>1</IdSaleReceipt>
      <ReceiptSegments>
        <SaleReceiptSegment z:Id="i16">
          <!--Data Removed-->
        </SaleReceiptSegment>
      </ReceiptSegments>
      <ReceiptTypeCode i:nil="true" />
      <RowCreated>2018-10-22T15:25:34.6771725</RowCreated>
      <RowGuid>1810a6b5-0ed6-e811-9766-90e2ba14d18e</RowGuid>
      <RowModifiedBy>1000</RowModifiedBy>
      <RowModifiedDate>2018-10-22T15:25:34.6771725</RowModifiedDate>
      <RowVersion>AAAAAAAAIII=</RowVersion>
    </SaleReceipt>
    <SaleReceipt z:Id="i17">
      <IdReceiptTypeCode>Customer</IdReceiptTypeCode>
      <IdRowStateCode>0</IdRowStateCode>
      <IdSale>8</IdSale>
      <IdSaleReceipt>2</IdSaleReceipt>
      <ReceiptSegments>
        <SaleReceiptSegment z:Id="i18">
          <!--Data Removed-->
        </SaleReceiptSegment>
      </ReceiptSegments>
      <ReceiptTypeCode i:nil="true" />
      <RowCreated>2018-10-22T15:25:34.6800439</RowCreated>
      <RowGuid>1a10a6b5-0ed6-e811-9766-90e2ba14d18e</RowGuid>
      <RowModifiedBy>1000</RowModifiedBy>
      <RowModifiedDate>2018-10-22T15:25:34.6800439</RowModifiedDate>
      <RowVersion>AAAAAAAAIIQ=</RowVersion>
    </SaleReceipt>
  </Receipts>
  <ReferencedBySales />
  <ReferencedSales />
  <RowCreated>2018-10-22T15:15:13.0180317</RowCreated>
  <RowGuid>bd931f45-0dd6-e811-9766-90e2ba14d18e</RowGuid>
  <RowModifiedBy>1000</RowModifiedBy>
  <RowModifiedDate>2018-10-22T15:25:35.0832346</RowModifiedDate>
  <RowStateCode i:nil="true" />
  <RowVersion>AAAAAAAAIJQ=</RowVersion>
  <SaleManagerSales />
  <Session z:Id="i19" xmlns:a="http://schemas.datacontract.org/2004/07/Delek.Store">
    <!--Data Removed-->
  </Session>
  <Signatures />
  <StartTime>2018-10-22T15:15:13.0180317</StartTime>
  <TotalTendered>-8.17</TotalTendered>
  <WorkflowStateCode i:nil="true" />
</Sale>

Here is the error the printer returns:

- <Result>


<Battery>0</Battery> 
  <Code>Error exists in the requested document syntax</Code> 
  <Status /> 
  <Success>Print Failed</Success> 
- <Res>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
- <soapenv:Body>
  <response success="false" code="SchemaError" status="0" battery="0" xmlns="http://www.epson-pos.com/schemas/2011/03/epos-print" /> 
  </soapenv:Body>
  </soapenv:Envelope>
  </Res>
  </Result>

Upvotes: 1

Views: 790

Answers (0)

Related Questions