[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: select first word

Subject: Re: select first word
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 18 Dec 2007 18:11:36 +0100
Re:  select first word
Florent Georges wrote:
Abel Braaksma wrote:

<xsl:value-of select="
translate(
substring-before(
substring-before(.,' '), ', '),
$from, $to)" />

If I am right (if I remember correctly) the input doesn't always have space or comma. So I would use the following instead (or the result could be empty):

translate(replace(., '([^, ]+).*', '$1'), $from, $to)

Thanks for pointing that out.
Yes, you are right about the input. But the OP has, I believe (from observation), only XSLT 1.0 and replace() is introduced as per XSLT 2.0.


The substring-before with the comma can be removed: if there's a comma it is followed by a space. Just add the comma to the translate function at the end, then it will be removed.

For the rest I'd probably choose something like this:

<!-- include comma, which is not matched, thus it will be deleted -->
<xsl:variable name="from" select="'abcdehijklmnorstuvyz{|HIJKA@,'" />
<xsl:variable name="to" select="'aaaaaeeeeiiiioooooEEEEAA'" />

<!-- with space -->
<xsl:template match="le[contains(., ' ')]">
<xsl:value-of select="translate(substring-before(., ' '), $from, $to)" />
</xsl:template>


<!-- without space -->
<xsl:template match="le">
   <xsl:value-of select="translate(., $from, $to)" />
</xsl:template>

The second one is the more generic one and will be called by the processor if there's no space in the content of the <le> element.

HTH,

Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.