[xsl] attribute value templates in elements fetched from a map?

Subject: [xsl] attribute value templates in elements fetched from a map?
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Sep 2020 20:08:32 -0000
Hello all --

The prototype has a whole bunch of individual templates which are mostly
the same except in match expression and in one of the values created;
the XML structure is mostly identical.  Many other things about the
process are being driven out of a map already, and I find myself
wondering if there's a way to (in effect) have a dynamic call-template
instruction; I want to keep the context, and maybe evaluate some
attribute value templates in the xml nodes provided, but which exact
nodes (and which exact attribute value templates) vary.

So a list item might look up:

<style>
  <style-name value="List" />
  <paragraphNumber>
        <level depth="{@depth - 1}"/>
  </paragraphNumber>
</style>

While a paragraph looks up:

<style>
  <style-name value="Paragraph" />
</style>

The transform function is computationally expensive and I'd have to pass
in arbitrary context (for things like determining heading depth); that
doesn't seem appealing.  xsl:evaluate can evaluate the XPath in the
current context but then there's no obvious way to get that value into
the markup:

<xsl:map-entry key="'list'">
    <style>
      <style-name val="List" />
      <paragraphNumber>
            <level depth="{$calculated[1]}"/>
      </paragraphNumber>
    </style>
</xsl:map-entry>

returns an error because $calculated is undefined.  (The idea there being to
evaluate all the XPath into a sequence of zero or more results and
positionally reference the results as a means of keeping the evaluation
generic.)  Driving this from a map is attractive, but not if I'm doing
serialize-regexp-parse-xml-fragment to get values into it.

Is there a sensible way to do this?

Thanks!

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread