Altova Mailing List Archives


Re: first letter in capital?

From: neil@------.--- (---- -----)
To: NULL
Date: 12/20/2003 12:48:00 PM
Nice one Dimitre, I'd also forgotten about a letter following a
bracket as well as a space character : the passing in delimiters is a
good solution;-)

On Sat, 20 Dec 2003 09:04:21 +0100, "Dimitre Novatchev"
<dnovatchev@y...> wrote:

>
>"Ikke" <Mail@N...> wrote in message
>news:brtbbb$l8v$1@n......
>> Below are two files (xml & xsl) and I want to make a string like:
>> "004.Lightning Crashes (Live).mp3"
>> My problem is that the string is like this "004.lightning crashes
>> (live).mp3"
>> How can I transform the first letter of every word to a capital (and the
>> rest in lower case)?
>
>Hi Ikke,
>
>This can be done using the (yet unpublished, source code given below) FXSL
>"str-split-word-del" template like this:
>
>This transformation:
>
><xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:ext="http://exslt.org/common"
>>
>   <xsl:import href="strSplitWordDel.xsl"/>
>
>   <xsl:output indent="yes" omit-xml-declaration="yes"/>
>   <xsl:variable name="vLower"
>        select="'abcdefgijklmnopqrstuvwxyz'"/>
>   <xsl:variable name="vUpper"
>        select="'ABCDEFGIJKLMNOPQRSTUVWXYZ'"/>
>
>    <xsl:template match="/">
>      <xsl:variable name="vwordNodes">
>        <xsl:call-template name="str-split-word-del">
>          <xsl:with-param name="pStr" select="/"/>
>          <xsl:with-param name="pDelimiters"
>                          select="', .(&#9;&#10;&#13;'"/>
>        </xsl:call-template>
>      </xsl:variable>
>
>      <xsl:apply-templates select="ext:node-set($vwordNodes)/*"/>
>    </xsl:template>
>
>    <xsl:template match="word">
>       <xsl:choose>
>         <xsl:when test="not(position() = last())">
>           <xsl:value-of
>           select="translate(substring(.,1,1),$vLower,$vUpper)"/>
>           <xsl:value-of select="substring(.,2)"/>
>         </xsl:when>
>         <xsl:otherwise>
>           <xsl:value-of select="."/>
>         </xsl:otherwise>
>       </xsl:choose>
>    </xsl:template>
>
>    <xsl:template match="delim">
>      <xsl:value-of select="."/>
>    </xsl:template>
>
></xsl:stylesheet>
>
>when applied to this source.xml:
>
><t>004.lightning crashes (live).mp3</t>
>
>produces the wanted result:
>
>004.Lightning Crashes (Live).mp3
>
>What "str-split-word-del" does is that it produces a node-set of tokens
>(words and delimiters). In this particular case the following node-set is
>produced:
>
>  <word>004</word>
>  <delim>.</delim>
>  <word>lightning</word>
>  <delim> </delim>
>  <word>crashes</word>
>  <delim> (</delim>
>  <word>live)</word>
>  <delim>.</delim>
>  <word>mp3</word>004.Lightning Crashes (Live).mp3
>
>Then I concatenate the string values of the list of "delim" and "word"
>elements, translating the first character of every (but the last) "word"
>into upper case.
>
>
>Here's the imported file strSplitWordDel.xsl:
>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>xmlns:ext="http://exslt.org/common"
>xmlns:str-split2words-func="f:str-split2words-func"
>exclude-result-prefixes="xsl ext str-split2words-func"
>>
>
>   <xsl:import href="str-foldl.xsl"/>
>
>   <str-split2words-func:str-split2words-func/>
>
>    <xsl:template name="str-split-word-del">
>      <xsl:param name="pStr"/>
>      <xsl:param name="pDelimiters"/>
>
>      <xsl:variable name="vsplit2wordsFun"
>                    select="document('')/*/str-split2words-func:*[1]"/>
>
>      <xsl:variable name="vrtfParams">
>       <delimiters><xsl:value-of select="$pDelimiters"/></delimiters>
>      </xsl:variable>
>
>      <xsl:variable name="vResult">
>       <xsl:call-template name="str-foldl">
>         <xsl:with-param name="pFunc" select="$vsplit2wordsFun"/>
>         <xsl:with-param name="pStr" select="$pStr"/>
>         <xsl:with-param name="pA0" select="ext:node-set($vrtfParams)"/>
>       </xsl:call-template>
>      </xsl:variable>
>
>      <xsl:copy-of select="ext:node-set($vResult)/*[position() > 1]"/>
>
>    </xsl:template>
>
>    <xsl:template match="str-split2words-func:*">
>      <xsl:param name="arg1" select="/.."/>
>      <xsl:param name="arg2"/>
>
>      <xsl:copy-of select="$arg1/*[1]"/>
>      <xsl:copy-of select="$arg1/*[position() >= 2
>                                 and position() != last()]"/>
>      <xsl:variable name="vLastToken" select="$arg1/*[position() >
>1][last()]"/>
>
>      <xsl:choose>
>        <xsl:when test="contains($arg1/*[1], $arg2)">
>          <xsl:choose>
>            <xsl:when test="$vLastToken[self::word]">
>              <xsl:copy-of select="$vLastToken"/>
>              <delim><xsl:copy-of select="$arg2"/></delim>
>            </xsl:when>
>            <xsl:otherwise>
>             <delim><xsl:value-of select="concat($vLastToken,
>$arg2)"/></delim>
>            </xsl:otherwise>
>          </xsl:choose>
>        </xsl:when>
>        <xsl:otherwise>
>          <xsl:choose>
>             <xsl:when test="$vLastToken[self::word]">
>               <word><xsl:value-of select="concat($arg1/word[last()],
>$arg2)"/></word>
>            </xsl:when>
>            <xsl:otherwise>
>             <xsl:copy-of select="$vLastToken"/>
>             <word><xsl:copy-of select="$arg2"/></word>
>            </xsl:otherwise>
>          </xsl:choose>
>        </xsl:otherwise>
>      </xsl:choose>
>    </xsl:template>
>
></xsl:stylesheet>
>
>Note that it uses another template (str-foldl) from FXSL. In case you
>haven't downloaded FXSL, here's the code for this last imported stylesheet:
>
>str-foldl.xsl:
>========
><xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:ext="http://exslt.org/common">
>    <xsl:template name="str-foldl">
>      <xsl:param name="pFunc" select="/.."/>
>      <xsl:param name="pA0"/>
>      <xsl:param name="pStr"/>
>
>      <xsl:choose>
>         <xsl:when test="not(string($pStr))">
>            <xsl:copy-of select="$pA0"/>
>         </xsl:when>
>         <xsl:otherwise>
>            <xsl:variable name="vFunResult">
>              <xsl:apply-templates select="$pFunc[1]">
>                <xsl:with-param name="arg0" select="$pFunc[position() >
>1]"/>
>                <xsl:with-param name="arg1" select="$pA0"/>
>                <xsl:with-param name="arg2" select="substring($pStr,1,1)"/>
>              </xsl:apply-templates>
>            </xsl:variable>
>
>            <xsl:call-template name="str-foldl">
>    <xsl:with-param name="pFunc" select="$pFunc"/>
>    <xsl:with-param name="pStr" select="substring($pStr,2)"/>
>    <xsl:with-param name="pA0" select="ext:node-set($vFunResult)"/>
>            </xsl:call-template>
>         </xsl:otherwise>
>      </xsl:choose>
>
>    </xsl:template>
></xsl:stylesheet>
>
>
>Hope this helped.
>
>
>Dimitre Novatchev.
>FXSL developer, XML Insider,
>
>http://fxsl.sourceforge.net/ -- the home of FXSL
>Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
>
>

======================================================== 
CaptionKit http://www.captionkit.com : Produce subtitled
internet media, transcripts and searchable video. Supports
Real Player, Quicktime and Windows Media Player.

VideoChat with friends online, get Freshly Toasted every 
day at http://www.fresh-toast.net : NetMeeting solutions 
for a connected world.

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.