Documentation
¶
Overview ¶
Package goxslt implements XSLT template matching and apply-templates logic. It uses goxml's node model and is designed to integrate with goxpath for pattern evaluation.
Index ¶
- func SerializeIndent(doc *goxml.XMLDocument, indentStr string) string
- func SerializeResult(doc *goxml.XMLDocument) string
- func SerializeWithOutput(doc *goxml.XMLDocument, output OutputProperties) string
- type AVT
- type AVTPart
- type AncestorQualifiedPattern
- type AnyNodeTest
- type BuiltInRuleSet
- type Cardinality
- type FunctionDef
- type GlobalDecl
- type Instruction
- type ItemType
- type KeyDefinition
- type KeyPattern
- type LiteralAttribute
- type LiteralElement
- type LiteralText
- type MatchContext
- type Mode
- func (m *Mode) AddRule(pattern Pattern, tmpl *TemplateBody, precedence int, priority float64, ...)
- func (m *Mode) ComputeRankings()
- func (m *Mode) GetNextRule(node goxml.XMLNode, ctx *MatchContext, currentRule *Rule) (*Rule, error)
- func (m *Mode) GetRule(node goxml.XMLNode, ctx *MatchContext) (*Rule, error)
- type NameTest
- type NamespaceWildcardTest
- type NodeKind
- type NodeKindTest
- type OutputProperties
- type PINameTest
- type Pattern
- type PredicatePattern
- type RecoveryPolicy
- type Rule
- type SequenceType
- type ShallowCopyRuleSet
- type SortKey
- type Stylesheet
- type TemplateBody
- type TemplateParam
- type TextOnlyCopyRuleSet
- type TransformContext
- func (tc *TransformContext) ApplyTemplates(mode *Mode, nodes []goxml.XMLNode) error
- func (tc *TransformContext) ApplyTemplatesWithParams(mode *Mode, nodes []goxml.XMLNode, paramValues map[string]goxpath.Sequence) error
- func (tc *TransformContext) ExecuteTemplate(tmpl *TemplateBody) error
- func (tc *TransformContext) MessageWriter() io.Writer
- type TransformOptions
- type TransformResult
- type UnionPattern
- type WildcardTest
- type XPathPattern
- type XSLAnalyzeString
- type XSLApplyImports
- type XSLApplyTemplates
- type XSLAttribute
- type XSLBreak
- type XSLCallTemplate
- type XSLCatch
- type XSLChoose
- type XSLComment
- type XSLCopy
- type XSLCopyOf
- type XSLElement
- type XSLForEach
- type XSLForEachGroup
- type XSLIf
- type XSLIterate
- type XSLMap
- type XSLMapEntry
- type XSLMessage
- type XSLNamespace
- type XSLNextIteration
- type XSLNextMatch
- type XSLNumber
- type XSLOnEmpty
- type XSLOnNonEmpty
- type XSLPerformSort
- type XSLProcessingInstruction
- type XSLResultDocument
- type XSLSequence
- type XSLSequenceConstructor
- type XSLSourceDocument
- type XSLText
- type XSLTry
- type XSLValueOf
- type XSLVariable
- type XSLWhen
- type XSLWherePopulated
- type XSLWithParam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SerializeIndent ¶
func SerializeIndent(doc *goxml.XMLDocument, indentStr string) string
SerializeIndent converts a result document to an indented XML string. An empty indentStr produces compact output without any added whitespace.
func SerializeResult ¶
func SerializeResult(doc *goxml.XMLDocument) string
SerializeResult converts a result document to an XML string.
func SerializeWithOutput ¶
func SerializeWithOutput(doc *goxml.XMLDocument, output OutputProperties) string
SerializeWithOutput converts a result document to a string using the given output properties.
Types ¶
type AVTPart ¶
AVTPart represents one piece of an Attribute Value Template. Exactly one of Text or Expr is non-empty.
type AncestorQualifiedPattern ¶
type AncestorQualifiedPattern struct {
BasePattern Pattern // for the node itself (e.g. "title")
UpperPattern Pattern // for the parent/ancestor (e.g. "book")
UseAncestor bool // false = parent only (/), true = any ancestor (//)
}
func (*AncestorQualifiedPattern) DefaultPriority ¶
func (p *AncestorQualifiedPattern) DefaultPriority() float64
func (*AncestorQualifiedPattern) Fingerprint ¶
func (p *AncestorQualifiedPattern) Fingerprint() string
func (*AncestorQualifiedPattern) Matches ¶
func (p *AncestorQualifiedPattern) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*AncestorQualifiedPattern) MatchesNodeKind ¶
func (p *AncestorQualifiedPattern) MatchesNodeKind() NodeKind
type AnyNodeTest ¶
type AnyNodeTest struct{}
func (*AnyNodeTest) DefaultPriority ¶
func (p *AnyNodeTest) DefaultPriority() float64
func (*AnyNodeTest) Fingerprint ¶
func (p *AnyNodeTest) Fingerprint() string
func (*AnyNodeTest) Matches ¶
func (p *AnyNodeTest) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*AnyNodeTest) MatchesNodeKind ¶
func (p *AnyNodeTest) MatchesNodeKind() NodeKind
type BuiltInRuleSet ¶
type BuiltInRuleSet interface {
Process(node goxml.XMLNode, ctx *TransformContext) error
}
BuiltInRuleSet defines the fallback behavior when no user template matches.
type Cardinality ¶
type Cardinality int
Cardinality specifies how many items are expected.
const ( CardOne Cardinality = iota // exactly 1 CardZeroOrOne // ? CardZeroOrMore // * CardOneOrMore // + )
type FunctionDef ¶
type FunctionDef struct {
Namespace string // resolved namespace URI
LocalName string // function name without prefix
Params []TemplateParam // positional parameters
Body *TemplateBody // compiled body
As *SequenceType // optional return type declaration
}
FunctionDef holds a compiled xsl:function definition.
type GlobalDecl ¶
type GlobalDecl struct {
IsParam bool
Param *TemplateParam
Var *XSLVariable
}
GlobalDecl represents a top-level parameter or variable in declaration order.
type Instruction ¶
type Instruction interface {
Execute(ctx *TransformContext) error
}
Instruction is a compiled XSLT instruction that can be executed during transformation.
type ItemType ¶
type ItemType int
ItemType identifies the expected type of an item in a SequenceType declaration.
type KeyDefinition ¶
type KeyDefinition struct {
Name string // key name (QName)
Match Pattern // pattern for nodes to index
Use string // XPath expression for the key value
Composite bool // composite="yes" means the key value is a sequence
}
KeyDefinition holds a compiled xsl:key declaration.
type KeyPattern ¶
type KeyPattern struct {
KeyName string // expanded key name
ValueExpr string // second argument (string literal or XPath expression)
Namespaces map[string]string // for XPath evaluation of ValueExpr
}
KeyPattern matches a node if it appears in the result of key(KeyName, ValueExpr). Used for match="key('k', 'val')" patterns.
func (*KeyPattern) DefaultPriority ¶
func (p *KeyPattern) DefaultPriority() float64
func (*KeyPattern) Fingerprint ¶
func (p *KeyPattern) Fingerprint() string
func (*KeyPattern) Matches ¶
func (p *KeyPattern) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*KeyPattern) MatchesNodeKind ¶
func (p *KeyPattern) MatchesNodeKind() NodeKind
type LiteralAttribute ¶
LiteralAttribute is an attribute on a literal result element.
type LiteralElement ¶
type LiteralElement struct {
Name string
Namespace string
Prefix string
Attributes []LiteralAttribute
Children []Instruction
}
LiteralElement creates an element in the result tree, then executes its child instructions inside it.
func (*LiteralElement) Execute ¶
func (instr *LiteralElement) Execute(ctx *TransformContext) error
type LiteralText ¶
LiteralText writes text to the result tree. When TVT is non-nil, the text is evaluated as a Text Value Template.
func (*LiteralText) Execute ¶
func (instr *LiteralText) Execute(ctx *TransformContext) error
type MatchContext ¶
type MatchContext struct {
Namespaces map[string]string
XPathEval func(expr string, node goxml.XMLNode) (bool, error)
XPathEvalSequence func(expr string, node goxml.XMLNode) ([]any, error)
KeyLookup func(keyName, valueExpr string, ns map[string]string) []goxml.XMLNode
}
MatchContext provides the context needed during pattern matching (namespace resolution etc.). Can be extended to wrap a goxpath.Context.
type Mode ¶
type Mode struct {
Name string
BuiltInRules BuiltInRuleSet
RecoveryPolicy RecoveryPolicy
// contains filtered or unexported fields
}
Mode is a collection of template rules, equivalent to an XSLT named or unnamed mode. It uses bucketing by node kind and element/attribute name for efficient lookup.
func NewMode ¶
func NewMode(name string, builtIn BuiltInRuleSet) *Mode
NewMode creates a new empty Mode.
func (*Mode) AddRule ¶
func (m *Mode) AddRule(pattern Pattern, tmpl *TemplateBody, precedence int, priority float64, sequence int, part int)
AddRule registers a new template rule in this mode.
func (*Mode) ComputeRankings ¶
func (m *Mode) ComputeRankings()
ComputeRankings assigns integer ranks to all rules so that runtime comparison is a single integer subtraction. Call after all rules have been added.
func (*Mode) GetNextRule ¶ added in v0.0.2
GetNextRule returns the next matching rule after currentRule (lower rank). Used for xsl:next-match.
type NameTest ¶
type NameTest struct {
LocalName string
NamespaceURI string // empty = no namespace constraint
Kind NodeKind
}
NameTest matches an element or attribute by local name (and optionally namespace URI). Corresponds to patterns like match="book" or match="svg:rect".
func (*NameTest) DefaultPriority ¶
func (*NameTest) Fingerprint ¶
func (*NameTest) MatchesNodeKind ¶
type NamespaceWildcardTest ¶
func (*NamespaceWildcardTest) DefaultPriority ¶
func (p *NamespaceWildcardTest) DefaultPriority() float64
func (*NamespaceWildcardTest) Fingerprint ¶
func (p *NamespaceWildcardTest) Fingerprint() string
func (*NamespaceWildcardTest) Matches ¶
func (p *NamespaceWildcardTest) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*NamespaceWildcardTest) MatchesNodeKind ¶
func (p *NamespaceWildcardTest) MatchesNodeKind() NodeKind
type NodeKind ¶
type NodeKind int
NodeKind identifies the type of an XML node.
func NodeKindOf ¶
NodeKindOf returns the NodeKind for a goxml.XMLNode.
type NodeKindTest ¶
type NodeKindTest struct {
Kind NodeKind
}
func (*NodeKindTest) DefaultPriority ¶
func (p *NodeKindTest) DefaultPriority() float64
func (*NodeKindTest) Fingerprint ¶
func (p *NodeKindTest) Fingerprint() string
func (*NodeKindTest) Matches ¶
func (p *NodeKindTest) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*NodeKindTest) MatchesNodeKind ¶
func (p *NodeKindTest) MatchesNodeKind() NodeKind
type OutputProperties ¶
type OutputProperties struct {
Method string // "xml", "html", "text"
Indent bool
Version string
OmitXMLDeclaration bool // omit-xml-declaration="yes" → true
}
OutputProperties holds xsl:output settings.
type PINameTest ¶ added in v0.0.2
type PINameTest struct {
Name string // target name to match
}
func (*PINameTest) DefaultPriority ¶ added in v0.0.2
func (p *PINameTest) DefaultPriority() float64
func (*PINameTest) Fingerprint ¶ added in v0.0.2
func (p *PINameTest) Fingerprint() string
func (*PINameTest) Matches ¶ added in v0.0.2
func (p *PINameTest) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*PINameTest) MatchesNodeKind ¶ added in v0.0.2
func (p *PINameTest) MatchesNodeKind() NodeKind
type Pattern ¶
type Pattern interface {
// Matches returns true if the node matches this pattern.
Matches(node goxml.XMLNode, ctx *MatchContext) bool
// Fingerprint returns a unique element/attribute name for bucketing,
// or "" if the pattern can match multiple names.
Fingerprint() string
// MatchesNodeKind returns the NodeKind this pattern can match, or
// NodeGeneric if it can match multiple kinds.
MatchesNodeKind() NodeKind
// DefaultPriority returns the default priority per the XSLT spec.
DefaultPriority() float64
}
Pattern is an interface for XSLT match patterns. Implementations test whether a given node matches the pattern.
type PredicatePattern ¶
type PredicatePattern struct {
BasePattern Pattern
PredicateExpr string // XPath expression from the match pattern
PredicateFunc func(node goxml.XMLNode, ctx *MatchContext) bool
}
func (*PredicatePattern) DefaultPriority ¶
func (p *PredicatePattern) DefaultPriority() float64
func (*PredicatePattern) Fingerprint ¶
func (p *PredicatePattern) Fingerprint() string
func (*PredicatePattern) Matches ¶
func (p *PredicatePattern) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*PredicatePattern) MatchesNodeKind ¶
func (p *PredicatePattern) MatchesNodeKind() NodeKind
type RecoveryPolicy ¶
type RecoveryPolicy int
RecoveryPolicy controls how ambiguous template matches are handled.
const ( RecoverSilently RecoveryPolicy = iota // first match wins, no warning RecoverWithWarning // warn, use last in declaration order DoNotRecover // error on ambiguity )
type Rule ¶
type Rule struct {
Template *TemplateBody
Precedence int // import precedence (higher = imported later)
Priority float64 // explicit or default priority
Sequence int // declaration order in the stylesheet
Part int // part number when a union pattern is split
// contains filtered or unexported fields
}
Rule represents a single template rule (an xsl:template with a match pattern).
type SequenceType ¶
type SequenceType struct {
Item ItemType
Cardinality Cardinality
}
SequenceType represents a parsed XSLT/XPath sequence type declaration such as "xs:integer", "node()*", or "xs:string?".
type ShallowCopyRuleSet ¶
type ShallowCopyRuleSet struct{}
func (*ShallowCopyRuleSet) Process ¶
func (b *ShallowCopyRuleSet) Process(node goxml.XMLNode, ctx *TransformContext) error
type SortKey ¶
type SortKey struct {
Select string // XPath expression; default "."
Order AVT // "ascending" (default) or "descending"
DataType AVT // "text" (default) or "number"
DataTypeExplicit bool // true if data-type was explicitly set in the stylesheet
Lang string // language tag for collation (e.g. "en", "de")
CaseOrder AVT // "upper-first" or "lower-first"
Stable string // "yes" or "no"
Collation string // collation URI
}
SortKey defines a sort criterion for xsl:sort.
type Stylesheet ¶
type Stylesheet struct {
DefaultMode *Mode
Modes map[string]*Mode
Output OutputProperties
NamedTemplates map[string]*TemplateBody
Functions map[string]*FunctionDef // key = "namespace localname"
Keys []KeyDefinition // xsl:key declarations
Namespaces map[string]string // prefix → URI from root element
ResultNamespaces map[string]string // prefix → URI to propagate to output elements
GlobalParams []TemplateParam // top-level xsl:param declarations
GlobalVars []XSLVariable // top-level xsl:variable declarations
GlobalDecls []GlobalDecl // params and variables in declaration order
BasePath string // directory for resolving document() URIs
StylesheetDoc *goxml.XMLDocument // parsed stylesheet document (for document(”))
}
Stylesheet holds the compiled XSLT stylesheet.
func Compile ¶
func Compile(xsltDoc *goxml.XMLDocument) (*Stylesheet, error)
Compile parses an XSLT stylesheet (already parsed as a goxml document) and returns a Stylesheet ready for transformation. Import/include directives cannot be resolved without a file path; use CompileFile for stylesheets that use xsl:import or xsl:include.
func CompileFile ¶
func CompileFile(xsltPath string) (*Stylesheet, error)
CompileFile compiles an XSLT stylesheet from a file path, enabling xsl:import and xsl:include resolution via relative href attributes.
type TemplateBody ¶
type TemplateBody struct {
Name string // optional template name
Params []TemplateParam // declared xsl:param elements
Instructions []Instruction // compiled instruction tree (after params)
As *SequenceType // optional return type declaration (as attribute)
}
TemplateBody represents the body of an xsl:template.
type TemplateParam ¶
type TemplateParam struct {
Name string
Select string
Children []Instruction
As *SequenceType // optional type declaration (as attribute)
}
TemplateParam is a declared parameter on a named template.
type TextOnlyCopyRuleSet ¶
type TextOnlyCopyRuleSet struct{}
func (*TextOnlyCopyRuleSet) Process ¶
func (b *TextOnlyCopyRuleSet) Process(node goxml.XMLNode, ctx *TransformContext) error
type TransformContext ¶
type TransformContext struct {
MatchCtx *MatchContext
CurrentMode *Mode
Modes map[string]*Mode
DefaultMode *Mode
CurrentNode goxml.XMLNode
CurrentItem goxpath.Item // non-nil when iterating over non-node items (arrays, maps, atomics)
SourceDoc *goxml.XMLDocument
XPath *goxpath.Parser
OutputStack []goxml.Appender // stack of output targets
Stylesheet *Stylesheet
MessageHandler func(text string, terminate bool) // optional callback for xsl:message
MapBuilder *goxpath.XPathMap // non-nil when inside xsl:map (xsl:map-entry appends here)
SecondaryDocuments map[string]*goxml.XMLDocument // href → secondary result documents
CurrentRule *Rule // currently executing template rule (for xsl:next-match)
// contains filtered or unexported fields
}
TransformContext holds the state during XSLT transformation.
func (*TransformContext) ApplyTemplates ¶
func (tc *TransformContext) ApplyTemplates(mode *Mode, nodes []goxml.XMLNode) error
ApplyTemplates selects the best template for each node and executes it.
func (*TransformContext) ApplyTemplatesWithParams ¶
func (*TransformContext) ExecuteTemplate ¶
func (tc *TransformContext) ExecuteTemplate(tmpl *TemplateBody) error
ExecuteTemplate executes a compiled template body.
func (*TransformContext) MessageWriter ¶
func (tc *TransformContext) MessageWriter() io.Writer
MessageWriter returns the writer for xsl:message output (defaults to os.Stderr).
type TransformOptions ¶
type TransformOptions struct {
MessageHandler func(text string, terminate bool) // callback for xsl:message
MessageWriter io.Writer // output for xsl:message (default os.Stderr)
Parameters map[string]goxpath.Sequence // stylesheet parameters (overrides xsl:param defaults)
InitialTemplate string // if set, call this named template instead of apply-templates on the document root
}
TransformOptions configures optional behavior for the transformation.
type TransformResult ¶
type TransformResult struct {
Document *goxml.XMLDocument // primary output
SecondaryDocuments map[string]*goxml.XMLDocument // href → document
Output OutputProperties // xsl:output settings
}
TransformResult holds the primary and any secondary result documents.
func Transform ¶
func Transform(ss *Stylesheet, sourceDoc *goxml.XMLDocument) (*TransformResult, error)
Transform applies the compiled stylesheet to the source document and returns the result.
func TransformWithOptions ¶
func TransformWithOptions(ss *Stylesheet, sourceDoc *goxml.XMLDocument, opts TransformOptions) (*TransformResult, error)
TransformWithOptions applies the stylesheet with configurable options.
type UnionPattern ¶
type UnionPattern struct {
Patterns []Pattern
}
UnionPattern matches if any sub-pattern matches. In XSLT, union patterns are typically split into separate rules during compilation (each branch gets its own Rule with the same template but different Part numbers). This type is provided for cases where you want to keep them together.
func (*UnionPattern) DefaultPriority ¶
func (p *UnionPattern) DefaultPriority() float64
func (*UnionPattern) Fingerprint ¶
func (p *UnionPattern) Fingerprint() string
func (*UnionPattern) Matches ¶
func (p *UnionPattern) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*UnionPattern) MatchesNodeKind ¶
func (p *UnionPattern) MatchesNodeKind() NodeKind
type WildcardTest ¶
type WildcardTest struct {
Kind NodeKind // NodeElement or NodeAttribute
}
func (*WildcardTest) DefaultPriority ¶
func (p *WildcardTest) DefaultPriority() float64
func (*WildcardTest) Fingerprint ¶
func (p *WildcardTest) Fingerprint() string
func (*WildcardTest) Matches ¶
func (p *WildcardTest) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*WildcardTest) MatchesNodeKind ¶
func (p *WildcardTest) MatchesNodeKind() NodeKind
type XPathPattern ¶ added in v0.0.2
func (*XPathPattern) DefaultPriority ¶ added in v0.0.2
func (p *XPathPattern) DefaultPriority() float64
func (*XPathPattern) Fingerprint ¶ added in v0.0.2
func (p *XPathPattern) Fingerprint() string
func (*XPathPattern) Matches ¶ added in v0.0.2
func (p *XPathPattern) Matches(node goxml.XMLNode, ctx *MatchContext) bool
func (*XPathPattern) MatchesNodeKind ¶ added in v0.0.2
func (p *XPathPattern) MatchesNodeKind() NodeKind
type XSLAnalyzeString ¶
type XSLAnalyzeString struct {
Select string // XPath expression → input string
Regex AVT // AVT → regex pattern
Flags AVT // AVT → regex flags (optional)
Matching []Instruction // body of xsl:matching-substring
NonMatching []Instruction // body of xsl:non-matching-substring
}
XSLAnalyzeString splits a string by a regular expression and processes matching and non-matching substrings separately. Corresponds to <xsl:analyze-string select="..." regex="...">.
func (*XSLAnalyzeString) Execute ¶
func (instr *XSLAnalyzeString) Execute(ctx *TransformContext) error
type XSLApplyImports ¶ added in v0.0.2
type XSLApplyImports struct {
WithParams []XSLWithParam // xsl:with-param children
}
XSLApplyImports applies imported template rules. Corresponds to <xsl:apply-imports/>.
func (*XSLApplyImports) Execute ¶ added in v0.0.2
func (instr *XSLApplyImports) Execute(ctx *TransformContext) error
type XSLApplyTemplates ¶
type XSLApplyTemplates struct {
Select string // XPath expression; empty means "child::node()"
Mode string // mode name; empty means default mode
Sorts []SortKey // optional sort keys
WithParams []XSLWithParam // xsl:with-param children
}
XSLApplyTemplates selects nodes via an XPath expression and applies matching templates. Corresponds to <xsl:apply-templates select="..."/>.
func (*XSLApplyTemplates) Execute ¶
func (instr *XSLApplyTemplates) Execute(ctx *TransformContext) error
type XSLAttribute ¶
type XSLAttribute struct {
Name AVT
Namespace AVT
Select string
Children []Instruction
}
XSLAttribute creates an attribute on the current result element. Corresponds to <xsl:attribute name="..." namespace="..." select="...">.
func (*XSLAttribute) Execute ¶
func (instr *XSLAttribute) Execute(ctx *TransformContext) error
type XSLBreak ¶ added in v0.0.3
type XSLBreak struct {
Children []Instruction // optional content to produce on break
}
XSLBreak terminates an xsl:iterate loop early. Corresponds to <xsl:break>.
func (*XSLBreak) Execute ¶ added in v0.0.3
func (instr *XSLBreak) Execute(ctx *TransformContext) error
type XSLCallTemplate ¶
type XSLCallTemplate struct {
Name string
WithParams []XSLWithParam
}
XSLCallTemplate calls a named template. Corresponds to <xsl:call-template name="...">.
func (*XSLCallTemplate) Execute ¶
func (instr *XSLCallTemplate) Execute(ctx *TransformContext) error
type XSLCatch ¶
type XSLCatch struct {
Errors string // space-separated error QNames or "*" (default: "*")
Children []Instruction // catch body
Select string // optional select expression
}
XSLCatch handles errors caught by xsl:try.
type XSLChoose ¶
type XSLChoose struct {
When []XSLWhen // one or more xsl:when branches
Otherwise []Instruction // optional xsl:otherwise body (nil if absent)
}
XSLChoose implements conditional processing with multiple branches. Corresponds to <xsl:choose>.
func (*XSLChoose) Execute ¶
func (instr *XSLChoose) Execute(ctx *TransformContext) error
type XSLComment ¶
type XSLComment struct {
Select string // optional select expression
Children []Instruction // body (used if Select is empty)
}
XSLComment creates a comment node in the result tree. Corresponds to <xsl:comment>.
func (*XSLComment) Execute ¶
func (instr *XSLComment) Execute(ctx *TransformContext) error
type XSLCopy ¶
type XSLCopy struct {
Children []Instruction
}
XSLCopy performs a shallow copy of the current node. Corresponds to <xsl:copy>...</xsl:copy>.
func (*XSLCopy) Execute ¶
func (instr *XSLCopy) Execute(ctx *TransformContext) error
type XSLCopyOf ¶
type XSLCopyOf struct {
Select string
}
XSLCopyOf copies nodes selected by an XPath expression to the result tree. Corresponds to <xsl:copy-of select="..."/>.
func (*XSLCopyOf) Execute ¶
func (instr *XSLCopyOf) Execute(ctx *TransformContext) error
type XSLElement ¶
type XSLElement struct {
Name AVT
Namespace AVT
Children []Instruction
}
XSLElement creates an element with a computed name. Corresponds to <xsl:element name="..." namespace="...">.
func (*XSLElement) Execute ¶
func (instr *XSLElement) Execute(ctx *TransformContext) error
type XSLForEach ¶
type XSLForEach struct {
Select string
Sorts []SortKey
Children []Instruction
}
XSLForEach iterates over a node set and executes child instructions. Corresponds to <xsl:for-each select="...">.
func (*XSLForEach) Execute ¶
func (instr *XSLForEach) Execute(ctx *TransformContext) error
type XSLForEachGroup ¶
type XSLForEachGroup struct {
Select string // XPath expression selecting the population
GroupBy string // XPath expression for grouping key
GroupAdjacent string // XPath expression for adjacent grouping key
GroupStartingPat Pattern // compiled pattern for group-starting-with
GroupEndingPat Pattern // compiled pattern for group-ending-with
Sorts []SortKey // optional sort keys
Children []Instruction // body to execute per group
}
XSLForEachGroup groups items and iterates over groups. Corresponds to <xsl:for-each-group select="..." group-by="...">.
func (*XSLForEachGroup) Execute ¶
func (instr *XSLForEachGroup) Execute(ctx *TransformContext) error
type XSLIf ¶
type XSLIf struct {
Test string // XPath expression returning boolean
Children []Instruction
}
XSLIf conditionally executes child instructions. Corresponds to <xsl:if test="...">.
func (*XSLIf) Execute ¶
func (instr *XSLIf) Execute(ctx *TransformContext) error
type XSLIterate ¶ added in v0.0.3
type XSLIterate struct {
Select string // XPath expression selecting the input sequence
Params []TemplateParam // iteration parameters (xsl:param)
Children []Instruction // body to execute per item
OnCompletion []Instruction // xsl:on-completion body (executed when sequence is exhausted)
}
XSLIterate processes a sequence with accumulating parameters. Corresponds to <xsl:iterate select="...">.
func (*XSLIterate) Execute ¶ added in v0.0.3
func (instr *XSLIterate) Execute(ctx *TransformContext) error
type XSLMap ¶
type XSLMap struct {
Children []Instruction
}
XSLMap creates an XPath map from xsl:map-entry children. Corresponds to <xsl:map>.
func (*XSLMap) BuildMap ¶
func (instr *XSLMap) BuildMap(ctx *TransformContext) (*goxpath.XPathMap, error)
BuildMap evaluates all children (including xsl:map-entry and any wrapping instructions like xsl:for-each) and collects the resulting map entries. It sets ctx.MapBuilder so that nested XSLMapEntry.Execute calls append to the map being built.
func (*XSLMap) Execute ¶
func (instr *XSLMap) Execute(ctx *TransformContext) error
type XSLMapEntry ¶
type XSLMapEntry struct {
Key string // XPath expression for the key
Select string // XPath expression for the value (optional)
Children []Instruction // body for value (used if Select is empty)
}
XSLMapEntry creates a single map entry within xsl:map. Corresponds to <xsl:map-entry key="..." select="...">.
func (*XSLMapEntry) Execute ¶
func (instr *XSLMapEntry) Execute(ctx *TransformContext) error
type XSLMessage ¶
type XSLMessage struct {
Terminate bool // if true, halt transformation after message
Select string // optional select expression
Children []Instruction // body (used if Select is empty)
}
XSLMessage outputs a message during transformation. Corresponds to <xsl:message terminate="yes|no">.
func (*XSLMessage) Execute ¶
func (instr *XSLMessage) Execute(ctx *TransformContext) error
type XSLNamespace ¶
type XSLNamespace struct {
Name AVT
Select string
Children []Instruction
}
XSLNamespace creates a namespace node on the current output element.
func (*XSLNamespace) Execute ¶
func (instr *XSLNamespace) Execute(ctx *TransformContext) error
Execute implements xsl:namespace by adding a namespace declaration to the current output element.
type XSLNextIteration ¶ added in v0.0.3
type XSLNextIteration struct {
WithParams []XSLWithParam
}
XSLNextIteration updates iteration parameters for the next iteration. Corresponds to <xsl:next-iteration>.
func (*XSLNextIteration) Execute ¶ added in v0.0.3
func (instr *XSLNextIteration) Execute(ctx *TransformContext) error
type XSLNextMatch ¶ added in v0.0.2
type XSLNextMatch struct {
WithParams []XSLWithParam // xsl:with-param children
}
XSLNextMatch finds the next matching template rule (lower priority/precedence) and executes it. Corresponds to <xsl:next-match/>.
func (*XSLNextMatch) Execute ¶ added in v0.0.2
func (instr *XSLNextMatch) Execute(ctx *TransformContext) error
type XSLNumber ¶
type XSLNumber struct {
Select string // XPath expression selecting the node to count from (default: context node)
Value string // XPath expression → direct number (bypasses count/from/level)
Count string // match pattern string: which nodes to count
From string // match pattern string: where to start counting
Level string // "single" (default), "multiple", "any"
Format string // format picture string (default "1")
CountPat Pattern // compiled count pattern (nil means use default)
FromPat Pattern // compiled from pattern (nil means no from)
}
XSLNumber generates a formatted number in the result tree. Corresponds to <xsl:number>.
func (*XSLNumber) Execute ¶
func (instr *XSLNumber) Execute(ctx *TransformContext) error
type XSLOnEmpty ¶
type XSLOnEmpty struct {
Children []Instruction
}
XSLOnEmpty provides fallback content when the parent sequence is empty.
func (*XSLOnEmpty) Execute ¶
func (instr *XSLOnEmpty) Execute(ctx *TransformContext) error
Execute implements xsl:on-empty. For now, this is a simplified version that just executes the children (proper empty-detection requires parent context).
type XSLOnNonEmpty ¶
type XSLOnNonEmpty struct {
Children []Instruction
}
XSLOnNonEmpty provides content only when the parent sequence is non-empty.
func (*XSLOnNonEmpty) Execute ¶
func (instr *XSLOnNonEmpty) Execute(ctx *TransformContext) error
Execute implements xsl:on-non-empty. For now, this is a simplified version.
type XSLPerformSort ¶ added in v0.0.2
type XSLPerformSort struct {
Select string // XPath expression for the input sequence (optional)
Sorts []SortKey // sort keys
Children []Instruction // sequence constructor (used when Select is empty)
}
XSLPerformSort sorts a sequence and writes it to the result tree. Corresponds to <xsl:perform-sort select="...">.
func (*XSLPerformSort) Execute ¶ added in v0.0.2
func (instr *XSLPerformSort) Execute(ctx *TransformContext) error
type XSLProcessingInstruction ¶
type XSLProcessingInstruction struct {
Name AVT
Select string
Children []Instruction
}
XSLProcessingInstruction creates a processing instruction in the result tree. Corresponds to <xsl:processing-instruction name="...">.
func (*XSLProcessingInstruction) Execute ¶
func (instr *XSLProcessingInstruction) Execute(ctx *TransformContext) error
type XSLResultDocument ¶
type XSLResultDocument struct {
Href AVT
Children []Instruction
}
XSLResultDocument redirects output to a secondary result document. Corresponds to <xsl:result-document href="...">.
func (*XSLResultDocument) Execute ¶
func (instr *XSLResultDocument) Execute(ctx *TransformContext) error
type XSLSequence ¶
type XSLSequence struct {
Select string
}
XSLSequence evaluates an XPath expression and adds items to the current sequence constructor. Corresponds to <xsl:sequence select="..."/>.
func (*XSLSequence) Execute ¶
func (instr *XSLSequence) Execute(ctx *TransformContext) error
type XSLSequenceConstructor ¶
type XSLSequenceConstructor struct {
Children []Instruction
}
XSLSequenceConstructor is a generic wrapper for a sequence of instructions.
func (*XSLSequenceConstructor) Execute ¶
func (instr *XSLSequenceConstructor) Execute(ctx *TransformContext) error
Execute implements a generic sequence constructor.
type XSLSourceDocument ¶
type XSLSourceDocument struct {
Href AVT
Children []Instruction
}
XSLSourceDocument loads an external document and executes its body with that document as the context node. Corresponds to <xsl:source-document href="..." streamable="yes|no">.
func (*XSLSourceDocument) Execute ¶
func (instr *XSLSourceDocument) Execute(ctx *TransformContext) error
Execute implements xsl:source-document by loading the document referenced by href and executing the children with that document as context node.
type XSLText ¶
XSLText writes literal text to the result tree. Corresponds to <xsl:text>...</xsl:text>. When TVT is non-nil, the text is evaluated as a Text Value Template.
func (*XSLText) Execute ¶
func (instr *XSLText) Execute(ctx *TransformContext) error
type XSLTry ¶
type XSLTry struct {
Children []Instruction // try body
Catches []XSLCatch // xsl:catch clauses
Select string // optional select expression (alternative to Children)
}
XSLTry executes a sequence constructor and catches dynamic errors.
func (*XSLTry) Execute ¶
func (instr *XSLTry) Execute(ctx *TransformContext) error
Execute implements xsl:try by executing the try body and catching errors.
type XSLValueOf ¶
type XSLValueOf struct {
Select string // XPath expression (optional if Children is set)
Children []Instruction // sequence constructor (used when Select is empty)
Separator string // item separator (default: single space in XSLT 2.0+)
}
XSLValueOf evaluates an XPath expression or its child sequence constructor and writes the string value to the result tree.
func (*XSLValueOf) Execute ¶
func (instr *XSLValueOf) Execute(ctx *TransformContext) error
type XSLVariable ¶
type XSLVariable struct {
Name string // variable name (without $)
Select string // XPath expression (used if Children is empty)
Children []Instruction // body (used if Select is empty, produces an RTF)
As *SequenceType // optional type declaration (as attribute)
}
XSLVariable binds a variable in the current scope. Corresponds to <xsl:variable name="..." select="..."> or with a body.
func (*XSLVariable) Execute ¶
func (instr *XSLVariable) Execute(ctx *TransformContext) error
type XSLWhen ¶
type XSLWhen struct {
Test string // XPath boolean expression
Children []Instruction // body to execute if test is true
}
XSLWhen is a single branch inside xsl:choose.
type XSLWherePopulated ¶
type XSLWherePopulated struct {
Children []Instruction
}
XSLWherePopulated executes children and includes output only if non-empty.
func (*XSLWherePopulated) Execute ¶
func (instr *XSLWherePopulated) Execute(ctx *TransformContext) error
Execute implements xsl:where-populated: execute children into a temporary document, include output only if non-empty.
type XSLWithParam ¶
type XSLWithParam struct {
Name string
Select string
Children []Instruction
}
XSLWithParam passes a parameter to a called template.