本文整理汇总了Golang中github.com/jbowtie/gokogiri/xml.Node.Attr方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Attr方法的具体用法?Golang Node.Attr怎么用?Golang Node.Attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbowtie/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.Attr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseTemplate
// ParseTemplate parses and compiles the xsl:template elements.
func (style *Stylesheet) ParseTemplate(node xml.Node) {
//add to template list of stylesheet
//parse mode, match, name, priority
mode := node.Attr("mode")
name := node.Attr("name")
match := node.Attr("match")
priority := node.Attr("priority")
p := 0.0
if priority != "" {
p, _ = strconv.ParseFloat(priority, 64)
}
// TODO: validate the name (duplicate should raise error)
template := &Template{Match: match, Mode: mode, Name: name, Priority: p, Node: node}
template.CompileContent(node)
// compile pattern
style.compilePattern(template, priority)
}
示例2: RegisterAttributeSet
func (style *Stylesheet) RegisterAttributeSet(node xml.Node) {
name := node.Attr("name")
res := CompileSingleNode(node)
res.Compile(node)
style.AttributeSets[name] = res
}
示例3: RegisterGlobalVariable
func (style *Stylesheet) RegisterGlobalVariable(node xml.Node) {
name := node.Attr("name")
_var := CompileSingleNode(node).(*Variable)
_var.Compile(node)
style.Variables[name] = _var
}
示例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.AttributeList() {
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)
}
}
}
}