Skip to content

Commit dbdbab6

Browse files
authored
libxslt/1.1.42 (#30)
* Release-as: libxslt/v1.0.0 * libxslt:use 1.1.42 * libxslt:demo * libxslt:ignore xsltSetCtxtLocaleHandlers * libxslt:rm unuse trimprefixes
1 parent 1c1e067 commit dbdbab6

32 files changed

+2549
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"unsafe"
7+
8+
"github.com/goplus/llpkg/libxslt"
9+
10+
"github.com/goplus/llgo/c"
11+
"github.com/goplus/llpkg/libxml2"
12+
)
13+
14+
func main() {
15+
libxml2.InitParser()
16+
17+
xml :=
18+
`<?xml version='1.0'?>
19+
<root>
20+
<person>
21+
<name>Alice</name>
22+
<age>25</age>
23+
</person>
24+
</root>`
25+
xslt := `<?xml version="1.0" encoding="UTF-8"?>
26+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
27+
<xsl:template match="/">
28+
<html>
29+
<body>
30+
<h1>个人信息</h1>
31+
<p>姓名: <xsl:value-of select="root/person/name"/></p>
32+
<p>年龄: <xsl:value-of select="root/person/age"/></p>
33+
</body>
34+
</html>
35+
</xsl:template>
36+
</xsl:stylesheet>
37+
`
38+
xmlDoc := libxml2.ReadMemory((*int8)(unsafe.Pointer(unsafe.StringData(xml))), c.Int(len(xml)), nil, nil, 0)
39+
xsltDoc := libxml2.ReadMemory((*int8)(unsafe.Pointer(unsafe.StringData(xslt))), c.Int(len(xslt)), nil, nil, 0)
40+
41+
if xmlDoc == nil || xsltDoc == nil {
42+
panic("cant read xml or xslt")
43+
}
44+
45+
stylesheet := libxslt.ParseStylesheetDoc(xsltDoc)
46+
if stylesheet == nil {
47+
panic("cant parse xslt")
48+
}
49+
result := libxslt.ApplyStylesheet(stylesheet, xmlDoc, (**int8)(unsafe.Pointer(uintptr(0))))
50+
if result == nil {
51+
panic("cant apply xslt")
52+
}
53+
54+
libxslt.SaveResultToFilename(c.Str("output.html"), result, stylesheet, 0)
55+
56+
libxml2.FreeDoc(xmlDoc)
57+
libxml2.FreeDoc(result)
58+
libxslt.FreeStylesheet(stylesheet)
59+
60+
libxslt.CleanupGlobals()
61+
libxml2.CleanupParser()
62+
63+
buf, err := os.ReadFile("./output.html")
64+
if err != nil {
65+
panic(err)
66+
}
67+
fmt.Println(string(buf))
68+
}

libxslt/attributes.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package libxslt
2+
3+
import (
4+
"github.com/goplus/llpkg/libxml2"
5+
_ "unsafe"
6+
)
7+
8+
//go:linkname ParseStylesheetAttributeSet C.xsltParseStylesheetAttributeSet
9+
func ParseStylesheetAttributeSet(style StylesheetPtr, cur libxml2.NodePtr)
10+
11+
//go:linkname FreeAttributeSetsHashes C.xsltFreeAttributeSetsHashes
12+
func FreeAttributeSetsHashes(style StylesheetPtr)
13+
14+
//go:linkname ApplyAttributeSet C.xsltApplyAttributeSet
15+
func ApplyAttributeSet(ctxt TransformContextPtr, node libxml2.NodePtr, inst libxml2.NodePtr, attributes *libxml2.Char)
16+
17+
//go:linkname ResolveStylesheetAttributeSet C.xsltResolveStylesheetAttributeSet
18+
func ResolveStylesheetAttributeSet(style StylesheetPtr)

libxslt/documents.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package libxslt
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"github.com/goplus/llpkg/libxml2"
6+
"unsafe"
7+
)
8+
9+
//go:linkname NewDocument C.xsltNewDocument
10+
func NewDocument(ctxt TransformContextPtr, doc libxml2.DocPtr) DocumentPtr
11+
12+
//go:linkname LoadDocument C.xsltLoadDocument
13+
func LoadDocument(ctxt TransformContextPtr, URI *libxml2.Char) DocumentPtr
14+
15+
//go:linkname FindDocument C.xsltFindDocument
16+
func FindDocument(ctxt TransformContextPtr, doc libxml2.DocPtr) DocumentPtr
17+
18+
//go:linkname FreeDocuments C.xsltFreeDocuments
19+
func FreeDocuments(ctxt TransformContextPtr)
20+
21+
//go:linkname LoadStyleDocument C.xsltLoadStyleDocument
22+
func LoadStyleDocument(style StylesheetPtr, URI *libxml2.Char) DocumentPtr
23+
24+
//go:linkname NewStyleDocument C.xsltNewStyleDocument
25+
func NewStyleDocument(style StylesheetPtr, doc libxml2.DocPtr) DocumentPtr
26+
27+
//go:linkname FreeStyleDocuments C.xsltFreeStyleDocuments
28+
func FreeStyleDocuments(style StylesheetPtr)
29+
30+
type LoadType c.Int
31+
32+
const (
33+
LOADSTART LoadType = 0
34+
LOADSTYLESHEET LoadType = 1
35+
LOADDOCUMENT LoadType = 2
36+
)
37+
38+
// llgo:type C
39+
type DocLoaderFunc func(*libxml2.Char, libxml2.DictPtr, c.Int, unsafe.Pointer, LoadType) libxml2.DocPtr
40+
41+
//go:linkname SetLoaderFunc C.xsltSetLoaderFunc
42+
func SetLoaderFunc(f DocLoaderFunc)

libxslt/exslt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package libxslt
2+
3+
import _ "unsafe"

libxslt/exsltconfig.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package libxslt
2+
3+
import _ "unsafe"
4+
5+
const LIBEXSLT_DOTTED_VERSION = "0.8.23"
6+
const LIBEXSLT_VERSION = 823
7+
const LIBEXSLT_VERSION_STRING = "823"
8+
const LIBEXSLT_VERSION_EXTRA = ""

libxslt/exsltexports.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package libxslt
2+
3+
import _ "unsafe"

libxslt/extensions.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package libxslt
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"github.com/goplus/llpkg/libxml2"
6+
"unsafe"
7+
)
8+
9+
/**
10+
* xsltInitGlobals:
11+
*
12+
* Initialize the global variables for extensions
13+
*
14+
*/
15+
//go:linkname InitGlobals C.xsltInitGlobals
16+
func InitGlobals()
17+
18+
// llgo:type C
19+
type StyleExtInitFunction func(StylesheetPtr, *libxml2.Char) unsafe.Pointer
20+
21+
// llgo:type C
22+
type StyleExtShutdownFunction func(StylesheetPtr, *libxml2.Char, unsafe.Pointer)
23+
24+
// llgo:type C
25+
type ExtInitFunction func(TransformContextPtr, *libxml2.Char) unsafe.Pointer
26+
27+
// llgo:type C
28+
type ExtShutdownFunction func(TransformContextPtr, *libxml2.Char, unsafe.Pointer)
29+
30+
//go:linkname RegisterExtModule C.xsltRegisterExtModule
31+
func RegisterExtModule(URI *libxml2.Char, initFunc ExtInitFunction, shutdownFunc ExtShutdownFunction) c.Int
32+
33+
//go:linkname RegisterExtModuleFull C.xsltRegisterExtModuleFull
34+
func RegisterExtModuleFull(URI *libxml2.Char, initFunc ExtInitFunction, shutdownFunc ExtShutdownFunction, styleInitFunc StyleExtInitFunction, styleShutdownFunc StyleExtShutdownFunction) c.Int
35+
36+
//go:linkname UnregisterExtModule C.xsltUnregisterExtModule
37+
func UnregisterExtModule(URI *libxml2.Char) c.Int
38+
39+
//go:linkname GetExtData C.xsltGetExtData
40+
func GetExtData(ctxt TransformContextPtr, URI *libxml2.Char) unsafe.Pointer
41+
42+
//go:linkname StyleGetExtData C.xsltStyleGetExtData
43+
func StyleGetExtData(style StylesheetPtr, URI *libxml2.Char) unsafe.Pointer
44+
45+
//go:linkname ShutdownCtxtExts C.xsltShutdownCtxtExts
46+
func ShutdownCtxtExts(ctxt TransformContextPtr)
47+
48+
//go:linkname ShutdownExts C.xsltShutdownExts
49+
func ShutdownExts(style StylesheetPtr)
50+
51+
//go:linkname XPathGetTransformContext C.xsltXPathGetTransformContext
52+
func XPathGetTransformContext(ctxt libxml2.XPathParserContextPtr) TransformContextPtr
53+
54+
/*
55+
* extension functions
56+
*/
57+
//go:linkname RegisterExtModuleFunction C.xsltRegisterExtModuleFunction
58+
func RegisterExtModuleFunction(name *libxml2.Char, URI *libxml2.Char, function libxml2.XPathFunction) c.Int
59+
60+
//go:linkname ExtModuleFunctionLookup C.xsltExtModuleFunctionLookup
61+
func ExtModuleFunctionLookup(name *libxml2.Char, URI *libxml2.Char) libxml2.XPathFunction
62+
63+
//go:linkname UnregisterExtModuleFunction C.xsltUnregisterExtModuleFunction
64+
func UnregisterExtModuleFunction(name *libxml2.Char, URI *libxml2.Char) c.Int
65+
66+
// llgo:type C
67+
type PreComputeFunction func(StylesheetPtr, libxml2.NodePtr, TransformFunction) ElemPreCompPtr
68+
69+
//go:linkname NewElemPreComp C.xsltNewElemPreComp
70+
func NewElemPreComp(style StylesheetPtr, inst libxml2.NodePtr, function TransformFunction) ElemPreCompPtr
71+
72+
//go:linkname InitElemPreComp C.xsltInitElemPreComp
73+
func InitElemPreComp(comp ElemPreCompPtr, style StylesheetPtr, inst libxml2.NodePtr, function TransformFunction, freeFunc ElemPreCompDeallocator)
74+
75+
//go:linkname RegisterExtModuleElement C.xsltRegisterExtModuleElement
76+
func RegisterExtModuleElement(name *libxml2.Char, URI *libxml2.Char, precomp PreComputeFunction, transform TransformFunction) c.Int
77+
78+
//go:linkname ExtElementLookup C.xsltExtElementLookup
79+
func ExtElementLookup(ctxt TransformContextPtr, name *libxml2.Char, URI *libxml2.Char) TransformFunction
80+
81+
//go:linkname ExtModuleElementLookup C.xsltExtModuleElementLookup
82+
func ExtModuleElementLookup(name *libxml2.Char, URI *libxml2.Char) TransformFunction
83+
84+
//go:linkname ExtModuleElementPreComputeLookup C.xsltExtModuleElementPreComputeLookup
85+
func ExtModuleElementPreComputeLookup(name *libxml2.Char, URI *libxml2.Char) PreComputeFunction
86+
87+
//go:linkname UnregisterExtModuleElement C.xsltUnregisterExtModuleElement
88+
func UnregisterExtModuleElement(name *libxml2.Char, URI *libxml2.Char) c.Int
89+
90+
// llgo:type C
91+
type TopLevelFunction func(StylesheetPtr, libxml2.NodePtr)
92+
93+
//go:linkname RegisterExtModuleTopLevel C.xsltRegisterExtModuleTopLevel
94+
func RegisterExtModuleTopLevel(name *libxml2.Char, URI *libxml2.Char, function TopLevelFunction) c.Int
95+
96+
//go:linkname ExtModuleTopLevelLookup C.xsltExtModuleTopLevelLookup
97+
func ExtModuleTopLevelLookup(name *libxml2.Char, URI *libxml2.Char) TopLevelFunction
98+
99+
//go:linkname UnregisterExtModuleTopLevel C.xsltUnregisterExtModuleTopLevel
100+
func UnregisterExtModuleTopLevel(name *libxml2.Char, URI *libxml2.Char) c.Int
101+
102+
/* These 2 functions are deprecated for use within modules. */
103+
//go:linkname RegisterExtFunction C.xsltRegisterExtFunction
104+
func RegisterExtFunction(ctxt TransformContextPtr, name *libxml2.Char, URI *libxml2.Char, function libxml2.XPathFunction) c.Int
105+
106+
//go:linkname RegisterExtElement C.xsltRegisterExtElement
107+
func RegisterExtElement(ctxt TransformContextPtr, name *libxml2.Char, URI *libxml2.Char, function TransformFunction) c.Int
108+
109+
/*
110+
* Extension Prefix handling API.
111+
* Those are used by the XSLT (pre)processor.
112+
*/
113+
//go:linkname RegisterExtPrefix C.xsltRegisterExtPrefix
114+
func RegisterExtPrefix(style StylesheetPtr, prefix *libxml2.Char, URI *libxml2.Char) c.Int
115+
116+
//go:linkname CheckExtPrefix C.xsltCheckExtPrefix
117+
func CheckExtPrefix(style StylesheetPtr, URI *libxml2.Char) c.Int
118+
119+
//go:linkname CheckExtURI C.xsltCheckExtURI
120+
func CheckExtURI(style StylesheetPtr, URI *libxml2.Char) c.Int
121+
122+
//go:linkname InitCtxtExts C.xsltInitCtxtExts
123+
func InitCtxtExts(ctxt TransformContextPtr) c.Int
124+
125+
//go:linkname FreeCtxtExts C.xsltFreeCtxtExts
126+
func FreeCtxtExts(ctxt TransformContextPtr)
127+
128+
//go:linkname FreeExts C.xsltFreeExts
129+
func FreeExts(style StylesheetPtr)
130+
131+
//go:linkname PreComputeExtModuleElement C.xsltPreComputeExtModuleElement
132+
func PreComputeExtModuleElement(style StylesheetPtr, inst libxml2.NodePtr) ElemPreCompPtr
133+
134+
/*
135+
* Extension Infos access.
136+
* Used by exslt initialisation
137+
*/
138+
//go:linkname GetExtInfo C.xsltGetExtInfo
139+
func GetExtInfo(style StylesheetPtr, URI *libxml2.Char) libxml2.HashTablePtr
140+
141+
/**
142+
* Test of the extension module API
143+
*/
144+
//go:linkname RegisterTestModule C.xsltRegisterTestModule
145+
func RegisterTestModule()
146+
147+
//go:linkname DebugDumpExtensions C.xsltDebugDumpExtensions
148+
func DebugDumpExtensions(output *c.FILE)

libxslt/extra.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package libxslt
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"github.com/goplus/llpkg/libxml2"
6+
_ "unsafe"
7+
)
8+
9+
//go:linkname FunctionNodeSet C.xsltFunctionNodeSet
10+
func FunctionNodeSet(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
11+
12+
//go:linkname Debug C.xsltDebug
13+
func Debug(ctxt TransformContextPtr, node libxml2.NodePtr, inst libxml2.NodePtr, comp ElemPreCompPtr)
14+
15+
//go:linkname RegisterExtras C.xsltRegisterExtras
16+
func RegisterExtras(ctxt TransformContextPtr)
17+
18+
//go:linkname RegisterAllExtras C.xsltRegisterAllExtras
19+
func RegisterAllExtras()

libxslt/functions.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package libxslt
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"github.com/goplus/llpkg/libxml2"
6+
"unsafe"
7+
)
8+
9+
//go:linkname XPathFunctionLookup C.xsltXPathFunctionLookup
10+
func XPathFunctionLookup(vctxt unsafe.Pointer, name *libxml2.Char, ns_uri *libxml2.Char) libxml2.XPathFunction
11+
12+
/*
13+
* Interfaces for the functions implementations.
14+
*/
15+
//go:linkname DocumentFunction C.xsltDocumentFunction
16+
func DocumentFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
17+
18+
//go:linkname KeyFunction C.xsltKeyFunction
19+
func KeyFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
20+
21+
//go:linkname UnparsedEntityURIFunction C.xsltUnparsedEntityURIFunction
22+
func UnparsedEntityURIFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
23+
24+
//go:linkname FormatNumberFunction C.xsltFormatNumberFunction
25+
func FormatNumberFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
26+
27+
//go:linkname GenerateIdFunction C.xsltGenerateIdFunction
28+
func GenerateIdFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
29+
30+
//go:linkname SystemPropertyFunction C.xsltSystemPropertyFunction
31+
func SystemPropertyFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
32+
33+
//go:linkname ElementAvailableFunction C.xsltElementAvailableFunction
34+
func ElementAvailableFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
35+
36+
//go:linkname FunctionAvailableFunction C.xsltFunctionAvailableFunction
37+
func FunctionAvailableFunction(ctxt libxml2.XPathParserContextPtr, nargs c.Int)
38+
39+
/*
40+
* And the registration
41+
*/
42+
//go:linkname RegisterAllFunctions C.xsltRegisterAllFunctions
43+
func RegisterAllFunctions(ctxt libxml2.XPathContextPtr)

libxslt/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/goplus/llpkg/libxslt
2+
3+
go 1.20
4+
5+
require (
6+
github.com/goplus/llgo v0.10.0
7+
github.com/goplus/llpkg/libxml2 v1.0.0
8+
)

0 commit comments

Comments
 (0)