Class: Saxon::XSLT::Invocation

Inherits:
Object
  • Object
show all
Defined in:
lib/saxon/xslt/invocation.rb

Overview

Represents the invocation of a compiled and loaded transformation, providing an idiomatic way to send the result a transformation to a particular Destination, or to serialize it directly to a file, string, or IO.

Instance Method Summary collapse

Constructor Details

#initialize(s9_transformer, invocation_lambda, raw) ⇒ Invocation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Invocation.



16
17
18
# File 'lib/saxon/xslt/invocation.rb', line 16

def initialize(s9_transformer, invocation_lambda, raw)
  @s9_transformer, @invocation_lambda, @raw = s9_transformer, invocation_lambda, raw
end

Instance Method Details

#raw?Boolean

Whether the transformation was invoked as a ‘raw’ transformation, where an XDM Value result will be returned without being wrapped in a Document node, and without sequence normalization.

Returns:

  • (Boolean)

    whether the transformation was invoked ‘raw’ or not



82
83
84
# File 'lib/saxon/xslt/invocation.rb', line 82

def raw?
  @raw
end

#serialize(io) { ... } ⇒ nil #serialize(path) { ... } ⇒ nil #serializeString

Serialize the result of the transformation. When called with a block, the block will be executed via instance-exec so that output properties can be set, e.g.

result.serialize {
  output_property[:indent] = 'yes'
}

Overloads:

  • #serialize(io) { ... } ⇒ nil

    Serialize the transformation to an IO

    Parameters:

    • io (File, IO)

      The IO to serialize to

    Yields:

    • the passed block bound via instance-exec to the new serializer

    Returns:

    • (nil)
  • #serialize(path) { ... } ⇒ nil

    Serialize the transformation to file path

    Parameters:

    • path (String, Pathname)

      The path of the file to serialize to

    Yields:

    • the passed block bound via instance-exec to the new serializer

    Returns:

    • (nil)
  • #serializeString

    Serialize the transformation to a String

    Returns:

    • (String)

      The serialized XdmValue



49
50
51
# File 'lib/saxon/xslt/invocation.rb', line 49

def serialize(path_or_io = nil, &block)
  serializer_destination(&block).serialize(path_or_io)
end

#to_destination(s9_destination) ⇒ nil

Send the result of the transformation to the supplied Destination

Parameters:

  • s9_destination (net.sf.saxon.s9api.Destination)

    the Saxon destination to use

Returns:

  • (nil)


72
73
74
75
# File 'lib/saxon/xslt/invocation.rb', line 72

def to_destination(s9_destination)
  invocation_lambda.call(s9_destination)
  nil
end

#to_sString

Serialize the result to a string using the options specified in <xsl:output/> in the XSLT

Returns:

  • (String)

    the serialized result of the transformation



24
25
26
# File 'lib/saxon/xslt/invocation.rb', line 24

def to_s
  serializer_destination.serialize
end

#xdm_valueSaxon::XDM::Value

Return the result of the transformation as an XDM Value, either as it is returned (if the XSLT::Executable was created with :raw => true), or wrapped in a Document node and sequence normalized.

Returns:



58
59
60
61
62
63
64
65
# File 'lib/saxon/xslt/invocation.rb', line 58

def xdm_value
  if raw?
    XDM.Value(invocation_lambda.call(nil))
  else
    invocation_lambda.call(s9_xdm_destination)
    XDM.Value(s9_xdm_destination.getXdmNode)
  end
end