|
Subject: Re: [xsl] Re: Generate identifier From: Vyacheslav Sedov <vyacheslav.sedov@xxxxxxxxx> Date: Thu, 7 Jan 2010 21:37:41 +0300 |
i prefer generate md5 as replacement for name ;)
2010/1/7 Vladimir Nesterovsky <vladimir@xxxxxxxxxxxxxxxxxxxx>:
>> I have missed the original post, but the effect of diacritics
>> is quite different from language to language.
>> Sometimes it is "only" an accent, in other languages it
>> changes the sound and sometimes meaning of a character.
>> What is a "Western" language? If you think of European
>> languages, there are some that do not use ASCII characters
>> at all (Cyrillic, Greek) and your method will not work.
>> So I would just drop them or replace them with an underscore.
>> Saves a lot of energy :-)
>
> You're absolutely right. It's not possible to build a perfect name
> suggestion from a string.
> In my case it's a COBOL name:
> cobol-word = [A-Za-z0-9]+ ([\-]+ [A-Za-z0-9]+)*
>
> And my current implementation is like this:
>
> B <!--
> B Creates a normalized name for a specified name components.
> B B $component - name components to generate normalized name for.
> B B $default-name - a default name in case a name cannot be built.
> B B Returns a normalized name.
> B -->
> B <xsl:function name="t:create-name" as="xs:string?">
> B <xsl:param name="components" as="xs:string*"/>
> B <xsl:param name="default-name" as="xs:string?"/>
>
> B <xsl:variable name="parts" as="xs:string*">
> B B <xsl:for-each select="$components">
> B B B <xsl:analyze-string
> B B B B regex="[A-Z0-9]+"
> B B B B flags="imx"
> B B B B select="
> B B B B B replace
> B B B B B (
> B B B B B B replace(normalize-unicode(upper-case(.), 'NFD'),
'Æ',
> 'AE'),
> B B B B B B '[\p{Sk}\p{Mc}\p{Me}\p{Mn}]',
> B B B B B B ''
> B B B B B )">
> B B B B <xsl:matching-substring>
> B B B B B <xsl:sequence select="."/>
> B B B B </xsl:matching-substring>
> B B B </xsl:analyze-string>
> B B </xsl:for-each>
> B </xsl:variable>
>
> B <xsl:sequence select="
> B B if (empty($parts)) then
> B B B $default-name
> B B else
> B B B string-join
> B B B (
> B B B B (
> B B B B B for
> B B B B B B $i in 1 to count($parts),
> B B B B B B $part in $parts[$i]
> B B B B B return
> B B B B B B if (($i = 1) and ($part lt ':') and ($part ge '0')) then
> B B B B B B B (($default-name, 'N')[1], $part)
> B B B B B B else
> B B B B B B B $part
> B B B B ),
> B B B B '-'
> B B B )"/>
> B </xsl:function>
>
> --
> Vladimir Nesterovsky
> http://www.nesterovsky-bros.com/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Re: Generate identifier, Vladimir Nesterovsky | Thread | Re: [xsl] Re: Generate identifier, G. Ken Holman |
| [xsl] Re: Generate identifier, Vladimir Nesterovsky | Date | RE: [xsl] Number of elements with a, J L |
| Month |