[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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

Subject: Re: [xsl] Combining translate() and apply-templates
From: Cynthia DeLaria <cdelaria@xxxxxxxxxxxxx>
Date: Thu, 27 Jan 2005 10:33:08 -0700 (GMT-07:00)

Yeah, I did notice this... I'm in the process of warning the client about this problem, which actually stemmed from someone's desire to go outside of the standards for displaying movie titles anyway. Thanks for the heads up! :)

-----Original Message-----
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Sent: Jan 27, 2005 9:31 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Combining translate() and apply-templates


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:value-of select="translate($title,$lower,$upper)" />
>so long as your upper and lower variables include the spanish

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

   <title>La <emph>Divorc<eacute />e</emph></title>

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

<xsl:template match="emph">

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


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