chrisdutz / gosaxon Goto Github PK
View Code? Open in Web Editor NEWAdvanced XSL for Go (using Saxon)
License: Apache License 2.0
Advanced XSL for Go (using Saxon)
License: Apache License 2.0
An issue has been identified when using the TransformWithExecutable
function inside handler functions of web services. The XSLT transformation runs correctly but the transformer executor process is not correctly killed which results in the generation of zombie (defunct) processes. A zombie (defunct) process is generated each time the transformer runs in the web service. These processes remain in their zombie (defunct) state until the web service is restarted.
Below is an example of a web service implementation that uses the TransformWithExecutable
in the handler of the /api/xslt_transform
endpoint:
package main
import (
"fmt"
"log"
"net/http"
"github.com/chrisdutz/gosaxon/library/pkg/gosaxon"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/api/xslt_transform", transform).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", router))
}
func transform(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Starting Transformer")
xml := "<fruits>\n <apple/>\n <pair/>\n</fruits>"
fmt.Printf("Sending XML:\n%s\n", xml)
xslt := "<xsl:stylesheet version=\"2.0\"\n xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xs=\"http://www.w3.org/1999/XSL/Transform\">\n <xsl:output method=\"xml\" indent=\"yes\"/>\n\n <xsl:template match=\"/fruits\">\n <apples-and-friends>\n <xsl:for-each select=\"*\">\n <xsl:choose>\n <xsl:when test=\"name() = 'pair'\">\n <apple-like-fruit/>\n </xsl:when>\n <xsl:otherwise>\n <xsl:copy-of select=\".\"/>\n </xsl:otherwise>\n </xsl:choose>\n </xsl:for-each>\n </apples-and-friends>\n </xsl:template>\n\n</xsl:stylesheet>"
fmt.Printf("Sending XSLT:\n%s\n", xslt)
result, err := gosaxon.TransformWithExecutable("/tmp/gosaxon-executor.lnx", []byte(xml), []byte(xslt))
if err != nil {
fmt.Printf("got error: %s", err.Error())
return
}
fmt.Printf("got result: \n%s", string(result))
w.Write(result)
}
Here is an example of what the generated zombie (defunct) processes look like:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 1496 0.0 0.0 0 0 pts/0 Z+ 12:07 0:00 [gosaxon-executo] <defunct>
user 1722 0.0 0.0 0 0 pts/0 Z+ 12:08 0:00 [gosaxon-executo] <defunct>
user 1730 0.0 0.0 0 0 pts/0 Z+ 12:08 0:00 [gosaxon-executo] <defunct>
user 1732 0.0 0.0 0 0 pts/0 Z+ 12:08 0:00 [gosaxon-executo] <defunct>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.