// 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) }
func (style *Stylesheet) RegisterAttributeSet(node xml.Node) { name := node.Attr("name") res := CompileSingleNode(node) res.Compile(node) style.AttributeSets[name] = res }
func (style *Stylesheet) RegisterGlobalVariable(node xml.Node) { name := node.Attr("name") _var := CompileSingleNode(node).(*Variable) _var.Compile(node) style.Variables[name] = _var }
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) } } } }