1

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>
Carthax
  • 119
  • 1
  • 12
  • AFAICT, this code requires a Microsoft processor. The freeformatter.com site uses a Saxon processor, so it won't run your `msxsl:script` (which is **not** part of XSLT 1.0). – michael.hor257k Jan 02 '19 at 22:11
  • The error message is definitely from Saxon. So please tell us what the C# code to invoke your transformation looks like. – Michael Kay Jan 03 '19 at 01:06
  • Use `XsltSettings` that allow script. – Martin Honnen Jan 03 '19 at 05:45
  • @MichaelKay, here is the code I use to call the XSLT transformation: `private static void Transformer(string transformationXSLT, XsltArgumentList args, string inputFile, string outputFile) { // Load the style sheet. XslCompiledTransform xslt = new XslCompiledTransform(true); xslt.Load(transformationXSLT, new XsltSettings(false, true), new XmlUrlResolver()); using (StreamWriter sw = new StreamWriter(outputFile)) { xslt.Transform(inputFile, args, sw); } }` – Carthax Jan 03 '19 at 14:33
  • Well, there's something very strange going on, and I can't debug it from the information supplied. That code doesn't invoke Saxon, and yet the error message looks precisely like a Saxon error message. – Michael Kay Jan 03 '19 at 16:12
  • Do you have a stack trace on that or can you post (in your question) minimal but complete samples of XSLT, XML and C# that allow others to reproduce the problem? Also what kind of C# code is that, Microsoft .NET framework? Do you get any better result with `extension-element-prefixes="msxsl"` as an attribute on the `xsl:stylesheet` element of the XSLT? – Martin Honnen Jan 03 '19 at 17:17
  • The post is edited. I don't get a stack trace when I run the code, because it doesn't crash. What I get is an error that the printer returns to me. I included it in the edit above. – Carthax Jan 03 '19 at 18:32

0 Answers0