Wiki source code of SetFile
Version 4.1 by Outhman Moustaghfir on 2024/09/25 12:14
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | ==== Purpose: ==== | ||
2 | |||
3 | The SetFile method is designed to store XML content in a database by saving it as a file and returning the file's unique identifier. | ||
4 | |||
5 | ==== How it Works: ==== | ||
6 | |||
7 | * The method takes XML content as input. | ||
8 | * It writes the XML content to a file. | ||
9 | * The file is saved in the database, and its file ID is returned for future reference. | ||
10 | |||
11 | |||
12 | ==== optional parameters: ==== | ||
13 | |||
14 | * **fileName** (optional): Specifies a custom name for the saved file. If not provided (null or empty), the file will be saved with its unique file ID as the name. | ||
15 | * **folder** (optional): Defines the folder where the file will be stored (e.g., "work", "out", etc.). If not specified (null or empty), the file will be placed in the default "work" folder. | ||
16 | |||
17 | |||
18 | {{code language="XML"}} | ||
19 | SetFile(xmlContent,fileName,folder) | ||
20 | {{/code}} | ||
21 | |||
22 | ==== Usage Example: ==== | ||
23 | |||
24 | Consider the following XSLT transformation that calls the SetFile method: | ||
25 | |||
26 | |||
27 | {{code language="XML"}} | ||
28 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
29 | xmlns:ixf="http://www.ixPath.com/Function" | ||
30 | xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
31 | xmlns:ix="localFunction" | ||
32 | xmlns:fn="http://www.w3.org/2005/xpath-functions" | ||
33 | version="2.0"> | ||
34 | |||
35 | <xsl:output method="xml" indent="yes"></xsl:output> | ||
36 | |||
37 | <!-- Start of the Transformation --> | ||
38 | <xsl:template match="/"> | ||
39 | <iXDOC> | ||
40 | <!-- Define the XML content you want to save --> | ||
41 | <xsl:variable name="xmlContent"> | ||
42 | <MyXML> | ||
43 | <XML> | ||
44 | <iXDoc> | ||
45 | <Invoice> | ||
46 | <InvoiceHeader> | ||
47 | <InvoiceNumber>123456</InvoiceNumber> | ||
48 | <InvoiceDate>2019-01-01</InvoiceDate> | ||
49 | <InvoiceDueDate>2019-01-31</InvoiceDueDate> | ||
50 | <InvoiceCurrency>USD</InvoiceCurrency> | ||
51 | <InvoiceTotal>1000.00</InvoiceTotal> | ||
52 | <InvoiceTax>100.00</InvoiceTax> | ||
53 | <InvoiceNet>900.00</InvoiceNet> | ||
54 | <InvoicePaid>0.00</InvoicePaid> | ||
55 | <InvoiceBalance>900.00</InvoiceBalance> | ||
56 | <InvoiceStatus>Open</InvoiceStatus> | ||
57 | <InvoiceTerms>Net 30</InvoiceTerms> | ||
58 | <InvoiceNotes>Thank you for your business!</InvoiceNotes> | ||
59 | </InvoiceHeader> | ||
60 | <!-- Additional Invoice Items --> | ||
61 | </Invoice> | ||
62 | </iXDoc> | ||
63 | </XML> | ||
64 | </MyXML> | ||
65 | </xsl:variable> | ||
66 | |||
67 | <!-- Call the SetFile method and pass the XML content --> | ||
68 | <xsl:variable name="fileId" select="ixf:SetFile($xmlContent)"></xsl:variable> | ||
69 | |||
70 | <!-- Output the ID of the saved file --> | ||
71 | <returnedFiles> | ||
72 | <fileId> | ||
73 | <xsl:value-of select="$fileId"></xsl:value-of> | ||
74 | </fileId> | ||
75 | </returnedFiles> | ||
76 | </iXDOC> | ||
77 | </xsl:template> | ||
78 | |||
79 | </xsl:stylesheet> | ||
80 | |||
81 | {{/code}} | ||
82 | |||
83 | ==== Output: ==== | ||
84 | |||
85 | The method will return the unique ID of the file saved in the database, which can be accessed as shown in the XSLT example. | ||
86 | |||
87 | ==== ==== |