Re: [xsl] dynamically applying templates

Subject: Re: [xsl] dynamically applying templates
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 13 Sep 2004 17:35:45 -0400
Bruce,

Sorry this is proving to be so cryptic.

At 04:44 PM 9/13/2004, you wrote:
On Sep 13, 2004, at 2:16 PM, Wendell Piez wrote:

I'm saying, in effect, there's nothing preventing you from selecting nodes in your config file, and matching them with templates, to achieve "dynamic template selection" if you want.

So you're saying match the config template and apply to mods with something like the following?


<xsl:template match="cs:title">
  <xsl:apply-templates select="//mods:titleInfo"/>
</xsl:template>

Unless you have mods:titleInfo elements somewhere in your input (either in the source file or in a configuration) ... no.


Select the config template and perform the mapping you want:

<xsl:template
   match="cs:title[parent::reftype/@name='book' and
                   ancestor::bibliography/@author-as-sort-order='yes'>
  <mods:titleInfo>
    Creates whatever output you want for this kind of title here;
    make generic, if you like, by including values of @after and
    so forth in place of literals....
  </mods:titleInfo>
</xsl:template>

where the node you are matching is in your config file:

<bibliography author-as-sort-order="yes">
  <entry>
    <reftype name="book">
      <title font-style="italic" after=", "/>
         [etc.]
    </reftype>
  </entry>
</bibliography>

<xsl:template match="cs:title">
  <xsl:apply-templates select="//mods:titleInfo" mode="bib"/>
</xsl:template>
...
<xsl:template match="mods:titleInfo" mode="bib">
  <span class="title">
    <xsl:apply-templates/>
  </span>
</xsl:template>

This won't work because that second template is not a mods:titleInfo element, and it won't ever be processed as such. It will only be applied if a mods:titleInfo node somewhere is selected (in mode 'bib'). (You could select a node from the stylesheet itself for processing, but any node addressed as "//mods:titleInfo" is going to be in the primary source; plus it's got the wrong name.)


Now of course, since you're using XSLT 2.0, you do have the option of *creating* a mods:titleInfo, and then processing that however you like ... that's a technique you've already seen:

<xsl:variable name="style-citation">
<xsl:apply-templates select="$styles/cs:citationstyle/cs:content/cs:citation"/>
</xsl:variable>
<xsl:apply-templates select="$style-citation" mode="bib"/>


where

<xsl:template match="cs:citation">
  <mods:titleInfo>
    ...
  </mods:titleInfo>
</xsl:template>

gives you a mods:titleInfo to process, and a template matching mods:titleInfo is then invoked by the apply-templates after the variable binding....

Maybe you're already doing this, and the approach is obvious ... if so, please forgive the intrusion.

I hope that helps.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


--+------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/ or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx> --+--

Current Thread