Re: [xsl] Combining translate() and apply-templates

Subject: Re: [xsl] Combining translate() and apply-templates
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 27 Jan 2005 11:31:22 -0500
Cynthia,

Watch out though: David's cunning solution won't work in every case:

At 02:33 PM 1/26/2005, you wrote:
<xsl:variable name="title">
  <xsl:apply-templates select="title"/>
</xsl:variable>

<xsl:value-of select="translate($title,$lower,$upper)" />

so long as your upper and lower variables include the spanish
characters.

only works as long as your input title, when processed by applying templates, needs to generate *only* a text value.


So if your input had

<new_rel>
  <title>La <emph>Divorc<eacute />e</emph></title>
  <rating>R</rating>
</new_rel>

that <emph> element would be lost, even if you also had

<xsl:template match="emph">
  <b>
    <xsl:apply-templates/>
  </b>
</xsl:template>

This is because when translate() operates on the variable $title it has to treat it as a string, so the result-tree-fragment created by applying templates to your title is "flattened" into its string value -- the <b> node generated by your template goes away.

I'm afraid a truly general solution to your problem requires multiple passes. This is because your solution to the representing-odd-characters problem straddles the line between markup and text ... you want to represent it as markup (in XSLT terms, "nodes"), yet process it as text.

Or you could constrain the input so that nothing like that emph will ever happen. Just thought it fair to warn....

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 ======================================================================

Current Thread