Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 XSLT extension function f:_copy-resource(src, type)
$$self{stylesheet}->register_function('http://dlmf.nist.gov/LaTeXML/functions', '_copy-resource', sub {
# values can be scalars or XML::LibXML::NodeList
my ($src, $type) = @_;
return Warn('malformed', '', $self, 'f:_copy-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
22 changes: 22 additions & 0 deletions lib/LaTeXML/resources/XSLT/LaTeXML-common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,28 @@
<func:result><xsl:value-of select="$url"/></func:result>
</func:function>

<!-- Return the destination url of a resource: f:resource(src, mimetype?)
When using latexmlpost, f:resource() is translated to a call to
LaTeXML::Post::XSLT::copyResource, which (if $src is not a URL) copies
$src to the destination directory and returns the location of the copy
relative to the destination directory. $mimetype, if present, is used to
search for $src in the LaTeXML distribution as well.
With other XSLT processors, f:resource returns $src unchanged.
-->
<func:function name="f:resource">
<xsl:param name="src"/>
<xsl:param name="mimetype"/>
<xsl:choose>
<!-- latexmlpost exports copyResource as 'f:_copy-resource' -->
<xsl:when test="function-available('f:_copy-resource')">
<func:result select="f:_copy-resource($src,$mimetype)"/>
</xsl:when>
<xsl:otherwise>
<func:result select="$src"/>
</xsl:otherwise>
</xsl:choose>
</func:function>

<func:function name="f:class-pref">
<xsl:param name="prefix"/>
<xsl:param name="string"/>
Expand Down