Transforming output to CSV format using a custom XSLT file
You can use custom XML transformations (XSLT files) to transform output data to your liking. This is useful if you need to change the format of the output data, or if you need to add additional information to the output. For example, you could use XML transforms to create output in comma-separated value (CSV) format. This example demonstrates how to create output in comma-separated value (CSV) format (hash-separated in this example), using the following XML:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" encoding="utf-8"/> <xsl:template match="/"> <xsl:value-of select="Batches/Batch/Documents/Document/Parties/Party[Type='supplier']/ExternalId"/> <xsl:text>#</xsl:text> <xsl:value-of select="Batches/Batch/Documents/Document/HeaderFields/HeaderField[Type='invoicenumber']/Text"/> <xsl:text>#</xsl:text> <xsl:value-of select="Batches/Batch/Documents/Document/HeaderFields/HeaderField[Type='invoicedate']/Text"/> <xsl:text>#</xsl:text> <xsl:value-of select="Batches/Batch/Documents/Document/HeaderFields/HeaderField[Type='invoicecurrency']/Text"/> <xsl:text>#</xsl:text> <xsl:value-of select="Batches/Batch/Documents/Document/HeaderFields/HeaderField[Type='invoicetotalvatincludedamount']/Text"/> <xsl:text>#</xsl:text> </xsl:template> </xsl:stylesheet>
The XSLT above exports five fields from each invoice to a text file and separates each value with a hash character (#). Line 3 specifies that the output is saved in a text file.
You can use XPath and the latest XML schema for ReadSoft Online to specify the fields you want to include in your output.
Paste the code above into a text editor, such as Notepad, and save the file with the extension .xslt.
If you use SFTP as the target system, the encoding of the XSLT file must match the encoding used by the target system. You must also specify this in the Encoding setting.
In this example, you can see the encoding is specified in two places; both must match the Encoding setting, which also matches the target system.
- Navigate to the Resources view and click ADD.
Use the dialog that appears to select the file you created. The file appears in the
Resources view after it uploads.
Resources that contain executable code must be approved by ReadSoft personnel before they can be used.
- Select a target system service that supports XSL transformations and click Configuration. These target-system services support XSL transformations:
- Use the dialog that appears to specify the XSLT file you created in step one in the XSL transformation box.
- Process an invoice through ReadSoft Online.
Connect to download the output data. For each invoice you process, an image file and a text file containing the
hash-separated output is created.
Transforming output with line items
Download this XSLT file to see an example similar to the one above, but with line items.