-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmpxmlresult2nodeexpressFullCRUD.xslt
75 lines (70 loc) · 3.31 KB
/
fmpxmlresult2nodeexpressFullCRUD.xslt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?xml version="1.0" encoding="utf-8"?>
<!--
Written by Gjermund G Thorsen 2017, all rights deserved
for the purpose of generating separate file for each NodeJS express/restify route node from FMPXMLRESULT
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no" />
<xsl:template match="fmp:FMPXMLRESULT">
<xsl:text>// To be called from app.js like this: app.use( `/</xsl:text><xsl:value-of select="$tableName" /><xsl:text>`, require( `./</xsl:text><xsl:value-of select="$tableName" /><xsl:text>` ) );
// or : app.use( `/</xsl:text><xsl:value-of select="$schemaTableName" /><xsl:text>`, require( `./</xsl:text><xsl:value-of select="$schemaTableName" /><xsl:text>` ) );
// or : app.use( `/</xsl:text><xsl:value-of select="$databaseName" /><xsl:text>`, require( `./</xsl:text><xsl:value-of select="$databaseName" /><xsl:text>` ) );
const
express = require( `express` ),
// restify = require( `restify` ),
routernode = express.Router();
routernode.route( `/` )
// Create resource
.post( ( req, res ) => {
res.status( 200 ).send( `Add a book using body` );
} )
// Read resource at random
.get( ( req, res ) => {
res.status( 200 ).send( `Get a resource at random` );
} );
// below is a redonkulous long list of field names; namely all of them for the table in question, please reduce to only include the one you actually need.
// routernode.route( `/:id` )
routernode.route( `</xsl:text><xsl:apply-templates select="fmp:METADATA/fmp:FIELD"/><xsl:text>` )
// Read resource
.get( ( req, res ) => {
res.status( 200 ).send( `Get the resource ${req.params.id}` );
} )
// Update resource
.patch( ( req, res ) => {
res.status( 200 ).send( `Update the resource ${req.params.id} using body for updates` );
} )
// Update replacing resource
.put( ( req, res ) => {
res.status( 200 ).send( `Replace the resource ${req.params.id} use body for replacement` );
} )
// Delete resource
// Typically implemented as an update mark for deletion.
.delete( ( req, res ) => {
res.status( 200 ).send( `Delete the resource ${req.params.id}` );
} );
module.exports = routernode;
</xsl:text>
</xsl:template>
<xsl:template match="fmp:METADATA/fmp:FIELD"><xsl:text>/:</xsl:text><xsl:value-of select="@NAME"/></xsl:template>
<xsl:variable name="schemaTableName">
<xsl:value-of select="fmp:FMPXMLRESULT/fmp:DATABASE/@NAME" />
<xsl:text>.</xsl:text>
<xsl:value-of select="fmp:FMPXMLRESULT/fmp:DATABASE/@LAYOUT" />
</xsl:variable>
<xsl:variable name="databaseName">
<xsl:value-of select="fmp:FMPXMLRESULT/fmp:DATABASE/@NAME" />
</xsl:variable>
<xsl:variable name="tableName">
<xsl:value-of select="fmp:FMPXMLRESULT/fmp:DATABASE/@LAYOUT" />
</xsl:variable>
<xsl:variable name="timeformat">
<xsl:value-of select="fmp:FMPXMLRESULT/fmp:DATABASE/@TIMEFORMAT" />
</xsl:variable>
</xsl:stylesheet>
<!--
========================================================================================
Copyright (c) 2008 - Gjermund Gusland Thorsen, released under the MIT License.
All rights deserved.
This piece comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
========================================================================================
-->