Beispiel #1
0
func checkPredRes(ret tree.Result, f *xpFilt, node tree.Node) (bool, error) {
	if num, ok := ret.(tree.Num); ok {
		if float64(f.proxPos[node.Pos()]) == float64(num) {
			return true, nil
		}
		return false, nil
	}

	if b, ok := ret.(tree.IsBool); ok {
		return bool(b.Bool()), nil
	}

	return false, fmt.Errorf("Cannot convert argument to boolean")
}
Beispiel #2
0
func findPrecedingSibling(x tree.Node, p *pathexpr.PathExpr, ret *[]tree.Node) {
	if x.GetNodeType() == tree.NtRoot {
		return
	}
	par := x.GetParent()
	ch := par.GetChildren()
	i := len(ch) - 1
	for x != ch[i] {
		i--
	}
	i--
	for i >= 0 {
		findSelf(ch[i], p, ret)
		i--
	}
}
Beispiel #3
0
func findFollowingSibling(x tree.Node, p *pathexpr.PathExpr, ret *[]tree.Node) {
	if x.GetNodeType() == tree.NtRoot {
		return
	}
	par := x.GetParent()
	ch := par.GetChildren()
	i := 0
	for x != ch[i] {
		i++
	}
	i++
	for i < len(ch) {
		findSelf(ch[i], p, ret)
		i++
	}
}
Beispiel #4
0
func findAncestor(x tree.Node, p *pathexpr.PathExpr, ret *[]tree.Node) {
	if x.GetNodeType() == tree.NtRoot {
		return
	}

	addNode(x.GetParent(), p, ret)
	findAncestor(x.GetParent(), p, ret)
}
Beispiel #5
0
func addNode(x tree.Node, p *pathexpr.PathExpr, ret *[]tree.Node) {
	add := false
	tok := x.GetToken()

	switch x.GetNodeType() {
	case tree.NtAttr:
		add = evalAttr(p, tok.(xml.Attr))
	case tree.NtChd:
		add = evalChd(p)
	case tree.NtComm:
		add = evalComm(p)
	case tree.NtElem, tree.NtRoot:
		add = evalEle(p, tok.(xml.StartElement))
	case tree.NtNs:
		add = evalNS(p, tok.(xml.Attr))
	case tree.NtPi:
		add = evalPI(p)
	}

	if add {
		*ret = append(*ret, x)
	}
}
Beispiel #6
0
func encTok(n tree.Node, e *xml.Encoder) error {
	switch n.GetNodeType() {
	case tree.NtAttr:
		return encAttr(n.GetToken().(xml.Attr), e)
	case tree.NtElem:
		return encEle(n.(tree.Elem), e)
	case tree.NtNs:
		return encNS(n.GetToken().(xml.Attr), e)
	case tree.NtRoot:
		for _, i := range n.(tree.Elem).GetChildren() {
			err := encTok(i, e)
			if err != nil {
				return err
			}
		}
		return nil
	}

	//case tree.NtChd, tree.NtComm, tree.NtPi:
	return e.EncodeToken(n.GetToken())
}
Beispiel #7
0
func findParent(x tree.Node, p *pathexpr.PathExpr, ret *[]tree.Node) {
	if x.GetNodeType() != tree.NtRoot {
		addNode(x.GetParent(), p, ret)
	}
}