[xsl] dynamically applying templates

Subject: [xsl] dynamically applying templates
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Sat, 11 Sep 2004 13:27:00 -0400
I'm still stuck on the remaining big problem in my stylesheets. I need to read an external file and use the structure of that file to determine processing. So, here's a fragment of the style file:

    <bibliography author-as-sort-order="yes">
      <entry>
	<reftype name="book">
	  <title font-style="italic" after=", "/>
	  <creator>
	    <names form="full"/>
	    <role/>
	  </creator>
	  <date before=" (" after=") ">
	    <year/>
	  </date>
	  <origin before="(" after="), ">
	    <place after=":"/>
	    <publisher/>
	  </origin>
	  <genre after=", "/>
	  <medium before="(" after="), "/>
	  <availability>
	    <physical-location before=", "/>
	    <url before=", "/>
	  </availability>
	</reftype>

What needs to happen, then, is that if the processor sees a "cs:creator" element (the style language is namespaced), it needs to map that to "mods:name."

Jeni was kind enough to help me figure out how to do this sort of thing to generate a css file to handle the formatting, but that's different because it's just taking the element names as strings to create the css class names and such.

She also suggested something like this awhile back:

<xsl:template match="cs:citationstyle/cs:content/cs:bibliography/cs:entry/cs:reftype/ cs:*">
<xsl:param name="style" as="element()" />
<xsl:variable name="source" as="element()" select="." />
<xsl:for-each select="$style/*">
<xsl:apply-templates select="$source/*[node-name(.) =
node-name(current())]">
<xsl:with-param name="style" select="." />
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>


The problem is that the element name in the style file needs to be the same as the template I need to apply in the main document.

So is there some way to adapt this to do a mapping like:

	cs:creator = mods:name
	cs:title = mods:titleInfo
	cs:origin = mods:originInfo

.... and so forth?

I had thought it might be nice to able to name each template and somehow apply those in the above, but nothing I try seems to be valid (e.g. I can't get away with <xsl:apply-templates name="$source/*[node-name(.) = node-name(current())]">).

Bruce

Current Thread