本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node.Namespace方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Namespace方法的具体用法?Golang Node.Namespace怎么用?Golang Node.Namespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ThomsonReutersEikon/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.Namespace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CompileSingleNode
func CompileSingleNode(node xml.Node) (step CompiledStep) {
switch node.NodeType() {
case xml.XML_ELEMENT_NODE:
ns := node.Namespace()
// element, extension namespace = extension
if ns == XSLT_NAMESPACE {
// element, XSLT namespace = instruction
switch node.Name() {
case "variable":
step = &Variable{Node: node}
case "param", "with-param":
step = &Variable{Node: node}
default:
step = &XsltInstruction{Name: node.Name(), Node: node}
}
} else {
// element other namespace = LRE
step = &LiteralResultElement{Node: node}
}
// text, CDATA node
case xml.XML_TEXT_NODE, xml.XML_CDATA_SECTION_NODE:
if !IsBlank(node) {
step = &TextOutput{Content: node.Content()}
}
}
return
}
示例2: UseCDataSection
func (context *ExecutionContext) UseCDataSection(node xml.Node) bool {
if node.NodeType() != xml.XML_ELEMENT_NODE {
return false
}
name := node.Name()
ns := node.Namespace()
for _, el := range context.Style.CDataElements {
if el == name {
return true
}
uri, elname := context.ResolveQName(el)
if uri == ns && name == elname {
return true
}
}
return false
}
示例3: Apply
// Evaluate an instruction and generate output nodes
func (i *XsltInstruction) Apply(node xml.Node, context *ExecutionContext) {
//push context if children to apply!
switch i.Name {
case "apply-templates":
scope := i.Node.Attr("select")
mode := i.Node.Attr("mode")
// #current is a 2.0 keyword
if mode != context.Mode && mode != "#current" {
context.Mode = mode
}
// TODO: determine with-params at compile time
var params []*Variable
for _, cur := range i.Children {
switch p := cur.(type) {
case *Variable:
if IsXsltName(p.Node, "with-param") {
p.Apply(node, context)
params = append(params, p)
}
}
}
// By default, scope is children of current node
if scope == "" {
children := context.ChildrenOf(node)
if i.sorting != nil {
i.Sort(children, context)
}
total := len(children)
oldpos, oldtotal := context.XPathContext.GetContextPosition()
oldcurr := context.Current
for i, cur := range children {
context.XPathContext.SetContextPosition(i+1, total)
//processNode will update Context.Current whenever a template is invoked
context.Style.processNode(cur, context, params)
}
context.XPathContext.SetContextPosition(oldpos, oldtotal)
context.Current = oldcurr
return
}
context.RegisterXPathNamespaces(i.Node)
e := xpath.Compile(scope)
// TODO: ensure we apply strip-space if required
nodes, err := context.EvalXPathAsNodeset(node, e)
if err != nil {
fmt.Println("apply-templates @select", err)
}
if i.sorting != nil {
i.Sort(nodes, context)
}
total := len(nodes)
oldpos, oldtotal := context.XPathContext.GetContextPosition()
oldcurr := context.Current
for i, cur := range nodes {
context.XPathContext.SetContextPosition(i+1, total)
context.Style.processNode(cur, context, params)
}
context.XPathContext.SetContextPosition(oldpos, oldtotal)
context.Current = oldcurr
case "number":
i.numbering(node, context)
case "text":
disableEscaping := i.Node.Attr("disable-output-escaping") == "yes"
content := i.Node.Content()
//don't bother creating a text node for an empty string
if content != "" {
r := context.Output.CreateTextNode(content)
if disableEscaping {
r.DisableOutputEscaping()
}
context.OutputNode.AddChild(r)
}
case "call-template":
name := i.Node.Attr("name")
t, ok := context.Style.NamedTemplates[name]
if ok && t != nil {
// TODO: determine with-params at compile time
var params []*Variable
for _, cur := range i.Children {
switch p := cur.(type) {
case *Variable:
if IsXsltName(p.Node, "with-param") {
p.Apply(node, context)
params = append(params, p)
}
}
}
t.Apply(node, context, params)
}
case "element":
ename := i.Node.Attr("name")
if strings.ContainsRune(ename, '{') {
ename = evalAVT(ename, node, context)
}
r := context.Output.CreateElementNode(ename)
ns := i.Node.Attr("namespace")
//.........这里部分代码省略.........
示例4: copyToOutput
func (i *XsltInstruction) copyToOutput(node xml.Node, context *ExecutionContext, recursive bool) {
switch node.NodeType() {
case xml.XML_TEXT_NODE:
if context.UseCDataSection(context.OutputNode) {
r := context.Output.CreateCDataNode(node.Content())
context.OutputNode.AddChild(r)
} else {
r := context.Output.CreateTextNode(node.Content())
context.OutputNode.AddChild(r)
}
case xml.XML_ATTRIBUTE_NODE:
aname := node.Name()
ahref := node.Namespace()
val := node.Content()
if ahref == "" {
context.OutputNode.SetAttr(aname, val)
} else {
context.OutputNode.SetNsAttr(ahref, aname, val)
}
case xml.XML_COMMENT_NODE:
r := context.Output.CreateCommentNode(node.Content())
context.OutputNode.AddChild(r)
case xml.XML_PI_NODE:
name := node.Attr("name")
r := context.Output.CreatePINode(name, node.Content())
context.OutputNode.AddChild(r)
case xml.XML_NAMESPACE_DECL:
//in theory this should work
//in practice it's a little complicated due to the fact
//that namespace declarations don't map to the node type
//very well
//will need to revisit
//context.OutputNode.DeclareNamespace(node.Name(), node.Content())
case xml.XML_ELEMENT_NODE:
aname := node.Name()
r := context.Output.CreateElementNode(aname)
context.OutputNode.AddChild(r)
ns := node.Namespace()
if ns != "" {
//TODO: search through namespaces in-scope
prefix, _ := context.Style.NamespaceMapping[ns]
r.SetNamespace(prefix, ns)
} else {
//may need to explicitly reset to empty namespace
def := context.DefaultNamespace(context.OutputNode)
if def != "" {
r.SetNamespace("", "")
}
}
//copy namespace declarations
for _, decl := range node.DeclaredNamespaces() {
r.DeclareNamespace(decl.Prefix, decl.Uri)
}
old := context.OutputNode
context.OutputNode = r
if recursive {
//copy attributes
for _, attr := range node.Attributes() {
i.copyToOutput(attr, context, recursive)
}
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
i.copyToOutput(cur, context, recursive)
}
}
context.OutputNode = old
case xml.XML_DOCUMENT_NODE:
if recursive {
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
i.copyToOutput(cur, context, recursive)
}
}
}
}
示例5: IsXsltName
// Returns true if the node is in the XSLT namespace
func IsXsltName(xmlnode xml.Node, name string) bool {
if xmlnode.Name() == name && xmlnode.Namespace() == XSLT_NAMESPACE {
return true
}
return false
}