forked from jbowtie/ratago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratago.go
59 lines (49 loc) · 1.12 KB
/
ratago.go
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
// The ratago command-line utility runs an input file through an XSLT stylesheet.
package main
import (
"flag"
"fmt"
"github.com/jbowtie/gokogiri/xml"
"github.com/jbowtie/ratago/xslt"
"os"
)
func usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] STYLESHEET INPUT\n", os.Args[0])
flag.PrintDefaults()
}
var indent = flag.Bool("indent", false, "Attempt to indent any XML output")
func main() {
flag.Usage = usage
flag.Parse()
if flag.NArg() < 2 {
usage()
return
}
//set some prefs based on flags
xslfile := flag.Arg(0)
inxml := flag.Arg(1)
style, err := xml.ReadFile(xslfile, xml.StrictParseOption)
if err != nil {
fmt.Println(err)
return
}
doc, err := xml.ReadFile(inxml, xml.StrictParseOption)
if err != nil {
fmt.Println(err)
return
}
//TODO: register some extensions (EXSLT, testing, debug)
//TODO: process XInclude if enabled
stylesheet, err := xslt.ParseStylesheet(style, xslfile)
if err != nil {
fmt.Println(err)
return
}
options := xslt.StylesheetOptions{*indent, nil}
output, err := stylesheet.Process(doc, options)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(output)
}