Skip to content

Commit

Permalink
Add f:resource() for adding resources from XSLT
Browse files Browse the repository at this point in the history
  • Loading branch information
xworld21 committed Apr 2, 2023
1 parent c3aea80 commit e56c19c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/LaTeXML/Common/XML/XSLT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ sub transform {
my ($self, $document, %params) = @_;
return $$self{stylesheet}->transform($document, %params); }

sub register_function {
my ($self, $uri, $name, $subref) = @_;
return $$self{stylesheet}->register_function($uri, $name, $subref); }

#======================================================================
1;
8 changes: 8 additions & 0 deletions lib/LaTeXML/Post/XSLT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ sub process {
return unless $$self{stylesheet};
# # Set up the Stylesheet parameters; making pathname parameters relative to document
my %params = %{ $$self{parameters} };
# set up f:resource(src, )
$$self{stylesheet}->register_function('http://dlmf.nist.gov/LaTeXML/functions', 'resource', sub {
# values can be scalars or XML::LibXML::NodeList
my ($src, $type) = @_;
return Warn('malformed', '', $self, 'resource() requires at least one argument') unless defined $src;
# string interpolation converts node lists to the concatenation of all the string values
return $self->copyResource($doc, "$src", defined $type ? ("$type") : ());
});
# Deal with any resources embedded within the document
if (my @resnodes = $doc->findnodes('//ltx:resource[@src]')) {
if ($$self{noresources}) {
Expand Down

0 comments on commit e56c19c

Please sign in to comment.