forked from goplus/llcppg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request goplus#156 from luoliwoshang/demotest/deps
llcppg:libxslt depend libxml
- Loading branch information
Showing
4 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"unsafe" | ||
|
||
"libxslt" | ||
|
||
"github.com/goplus/llgo/c" | ||
libxml2 "github.com/luoliwoshang/llcppg-libxml" | ||
) | ||
|
||
func main() { | ||
libxml2.XmlInitParser() | ||
|
||
xml := | ||
`<?xml version='1.0'?> | ||
<root> | ||
<person> | ||
<name>Alice</name> | ||
<age>25</age> | ||
</person> | ||
</root>` | ||
xslt := `<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<xsl:template match="/"> | ||
<html> | ||
<body> | ||
<h1>个人信息</h1> | ||
<p>姓名: <xsl:value-of select="root/person/name"/></p> | ||
<p>年龄: <xsl:value-of select="root/person/age"/></p> | ||
</body> | ||
</html> | ||
</xsl:template> | ||
</xsl:stylesheet> | ||
` | ||
xmlDoc := libxml2.XmlReadMemory((*int8)(unsafe.Pointer(unsafe.StringData(xml))), c.Int(len(xml)), nil, nil, 0) | ||
xsltDoc := libxml2.XmlReadMemory((*int8)(unsafe.Pointer(unsafe.StringData(xslt))), c.Int(len(xslt)), nil, nil, 0) | ||
|
||
if xmlDoc == nil || xsltDoc == nil { | ||
panic("cant read xml or xslt") | ||
} | ||
|
||
stylesheet := libxslt.XsltParseStylesheetDoc(xsltDoc) | ||
if stylesheet == nil { | ||
panic("cant parse xslt") | ||
} | ||
result := libxslt.XsltApplyStylesheet(stylesheet, xmlDoc, (**int8)(unsafe.Pointer(uintptr(0)))) | ||
if result == nil { | ||
panic("cant apply xslt") | ||
} | ||
|
||
libxslt.XsltSaveResultToFilename(c.Str("output.html"), result, stylesheet, 0) | ||
|
||
libxml2.XmlFreeDoc(xmlDoc) | ||
libxml2.XmlFreeDoc(result) | ||
libxslt.XsltFreeStylesheet(stylesheet) | ||
|
||
libxslt.XsltCleanupGlobals() | ||
libxml2.XmlCleanupParser() | ||
|
||
buf, err := os.ReadFile("./output.html") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(string(buf)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "libxslt", | ||
"cflags": "$(pkg-config --cflags libxslt)", | ||
"libs": "$(pkg-config --libs libxslt)", | ||
"include": [ | ||
"libxslt/variables.h", | ||
"libxslt/functions.h", | ||
"libxslt/xsltutils.h", | ||
"libxslt/templates.h", | ||
"libxslt/pattern.h", | ||
"libxslt/preproc.h", | ||
"libxslt/extra.h", | ||
"libxslt/documents.h", | ||
"libxslt/imports.h", | ||
"libxslt/keys.h", | ||
"libxslt/transform.h", | ||
"libxslt/attributes.h", | ||
"libxslt/security.h", | ||
"libxslt/extensions.h", | ||
"libxslt/xsltInternals.h", | ||
"libexslt/exslt.h", | ||
"libxslt/numbersInternals.h", | ||
"libxslt/namespaces.h", | ||
"libxslt/xslt.h", | ||
"libxslt/xsltlocale.h", | ||
"libexslt/exsltexports.h", | ||
"libxslt/xsltconfig.h", | ||
"libxslt/xsltexports.h", | ||
"libexslt/exsltconfig.h" | ||
], | ||
"deps": ["github.com/luoliwoshang/llcppg-libxml"], | ||
"trimPrefixes": [], | ||
"cplusplus": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters