I'm using XSLT 1.0 (with lxml.etree and Python) to transform XML. I can use "http://exslt.org/
" extensions (common, strings and so on), but not XSLT 2.0.
The input XML has two main sections - a series of nested rules which have name="xxx" attributes, and a set of mappings that extend the definition of each "xxx". The XML look like:
<onerule name="xxx" startval="1" endval="5" maptype="full"/>
<onerule name="yyy" startval="1" endval="5" maptype="full"/>
<thisrule name="yyy" startval="1" endval="5" maptype="partial"/>
<onemap name="xxx" attr1="8">
<onemap name="yyy" attr1="4">
As you can see, the rule names can appear multiple times in the "rules" section, but will only appear once in the "maps" section. The format is fixed - I'd love to change it but cannot.
I already have code in my templates which gets a map entry when parsing an entry from the main rules section, assuming that the element has a "name=" attribute:
<xsl:variable name="myattr1" select="/process/maps/onemap[@name = current()/@name]/@attr1" />
and I can then use the $myattr1 variable in the rest of the template.
What I am trying to do now is to get the attr1 attribute for an entry based on a variable name, not on being the current rule being parsed. The variable value is actually being extracted from another attribute which has a comma-separated string of map names.
What do I need to replace the "[@name = current()/@name]" section with, to base the selection on the values of, say, the $first
xsl variable? Or do I need to do this a different way?
I have tried the simplistic ways - "[@name = $first]", "[@name = $first/@name]" and so on, and have tried using select="dyn:evaluate('/pro
me = $first]/@name')" (after adding xmlns:dyn="http://exslt.org/dynamic
to the stylesheet header). They all either return nothing, or an evaluation error. I keep thinking that there is something obvious that I am missing.