RE: [XSLT2] OB06 xsl:analyze-string

Hi Dave,

thanks for your support. :-)

> <xsl:function name="dp:escHash" as="xs:string">
>   <xsl:param name="str" as="xs:string"/>
>  
> 
>  <xsl:variable name="t0">
>         <xsl:value-of select="if (contains($str,'{' ))
>                               then replace($str, '\{', '{day}{of}') 
>         else $str"/>
>   </xsl:variable>
> etc.
> 
> 
> to achieve the objective of this proposal, multiple replacements
> in the same string, I had 8 sequences of variable creation
> based on the previous substitution.

However, why are doing it in this rather long-winded way?

<xsl:variable ..
   <xsl:value-of select= ..
   
can be written in your case as

<xsl:variable select= ..

Then: why are you testing for the occurance of the { character?
I think, simply calling the replace function (regardless whether
there is a substring to replace or not) will give you the same result.

<xsl:variable select="replace($str, '\{', '{day}{of}')" />

If you need 8 replacements then nested invocations of replace should
do it:

replace(replace(replace(....)
                ...
        '\{', '{day}{of}')

This is still a little bit messy, but probably shorter than using
xsl:analyze-string, even with my proposal.
xsl:analyze-string is useful for replacements with markup 
(aka complex content).

(Which means that in my last email one of my my use cases -- the XML
to HTML verbatim formatter -- is not a real use case, because most of
the replacements used only characters. However, the second example --
code syntax highlighting -- still stands.)

Regards,
Oliver

/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@informatik.hu-berlin.de             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/

Received on Monday, 9 February 2004 04:51:51 UTC