package main import ( "fmt" "github.com/jbowtie/gokogiri" "github.com/jbowtie/gokogiri/xml" "github.com/jbowtie/gokogiri/xpath" "github.com/pebbe/util" ) var ( xmldoc = ` banaan ansjovis apenootjes ` x = util.CheckErr ) type varScope struct { vars map[string]interface{} } func (v *varScope) ResolveVariable(local, namespace string) interface{} { return v.vars[local] } func (v *varScope) IsFunctionRegistered(a, b string) bool { return false } func (v *varScope) ResolveFunction(a, b string) xpath.XPathFunction { return nil } func main() { doc, err := gokogiri.ParseXml([]byte(xmldoc)) x(err) root := doc.Root() chimps, err := root.Search(`//chimp`) x(err) cats, err := root.Search(`//cat`) x(err) foods, err := root.SearchWithVariables( `$chimps/food | $cats/food`, &varScope{ vars: map[string]interface{}{ "chimps": xml.Nodeset(chimps).ToPointers(), "cats": xml.Nodeset(cats).ToPointers(), }, }) x(err) for _, food := range foods { fmt.Println(food) } doc.Free() }