Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Wednesday August 31, 2005
07:06 PM

XSLT Ugliness

[ #26545 ]

Here's the template I came up with to translate the first character of a string to upper case and subsequent underscores to spaces:

  <xsl:template name="proper-case-name">
    <xsl:param name="expr"/>
    <xsl:variable name="uc"
      select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <xsl:variable name="lc"
      select="'abcdefghijklmnopqrstuvwxyz'"/>
    <xsl:value-of
      select="concat(
          translate(substring($expr,1,1),$lc,$uc),
          translate(substring($expr, 2), '_', ' ')
      )"/>
  </xsl:template>

Yuck. Can't even get it Unicode aware (this is processed both client and server side).

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • A couple of years back I went through a moderate amount of pain to get XSLT into my head. I wasn't an uber-guru but I could get stuff done without just randomly thrashing about.

    Since then I've not had to do any XML that XML::Simple couldn't handle.

    A week or so ago I needed to munge some OPML in a way that suited itself to an XSLT solution. Wrote failing test then switched to my code window to discover that.... XSLT had completely fallen out of my head. Seriously. I had to go dig out my Peacock O'Reilly befo
  • You can translate Unicode characters but it's going to be very ugly. You simply put the appropriate Unicode characters into the tranlation string. This will require massive amounts of your time to track down all of the necessary Unicode characters in upper and lower case. Not exactly something I'd want to do.
  • How are you invoking your stylesheet? Is it being run from a Perl script (via XML::LibXSLT)? Can you expose a Perl function as an extension function into the stylesheet and just punt the capitalization to something a little more amenable to solving the problem?
    • I would like to do that but I've set it up to have the browser to handle the XSLT and falling back to server side processing if the browser cannot process XSLT. If I keep running to stuff like this, perhaps I'll rethink it.

      • The devious hack to leave this on the server would be to use XPath’s document() function to call back to the server. Stick the string in a query paramater and…