[xsl] Re: processing text nodes one character at a time

Subject: [xsl] Re: processing text nodes one character at a time
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Tue, 26 Sep 2006 18:17:06 -0700
On 9/26/06, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
On 9/26/06, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> The original poster asked:
>
>  How to output a specific character in front of every character in a
> given string?
>
> Part I:
> ====
> This is a problem that is easily solved with FXSL. the solution is
> this one-liner:
>
>
>   f:str-map(f:flip(f:concat2(), '|'), string(/*))

Part II
====
Of course, it needs to be put into a stylesheet:


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 xmlns:f="http://fxsl.sf.net/";
 xmlns:testmap="testmap"
exclude-result-prefixes="xs f"
>
 <xsl:import href="../f/func-str-dvc-map.xsl"/>
 <xsl:import href="../f/func-curry.xsl"/>
 <xsl:import href="../f/func-flip.xsl"/>

 <!-- To be applied on text.xml -->
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
   <xsl:sequence select=
    "f:str-map(f:flip(f:concat2(), '|'), string(/*))"
    />
 </xsl:template>


and this woud be the place to put the </xsl:stylesheeet> end-tag when the definition of the various f:concat2() functions were part of FXSL (I'll be uploading them shortly).

And I will send the function definitions in Part III.

The reasons of this splitting of what originally was one reply is that
it never came through, regardless of three attempts -- gmail somehow
desides to use bin64 encoding, which xsl-list rejects. Sorry for the
inconvenience...


Part III =====

and this woud be the place to put the </xsl:stylesheeet> end-tag when
the definition of the various f:concat2() functions were part of FXSL
(I'll be uploading them shortly).

Right at this moment we cannot import them but they are inline:

  <xsl:function name="f:concat2" as="xs:string">
    <xsl:param name="pStr1" as="xs:string"/>
    <xsl:param name="pStr2" as="xs:string"/>

    <xsl:sequence select="concat($pStr1, $pStr2)"/>
  </xsl:function>

  <xsl:function name="f:concat2" as="element()">
    <xsl:param name="pStr1" as="xs:string"/>

    <xsl:sequence select="f:curry(f:concat2(),2,$pStr1)"/>
  </xsl:function>

  <xsl:function name="f:concat2" as="element()">
    <f:concat2/>
  </xsl:function>

  <xsl:template match="f:concat2" mode="f:FXSL">
    <xsl:param name="arg1" as="xs:string"/>
    <xsl:param name="arg2" as="xs:string"/>

    <xsl:sequence select="f:concat2($arg1, $arg2)"/>
  </xsl:template>

</xsl:stylesheet>


The sample input on which this stylesheet was applied can be found at:


http://sourceware.org/ml/xsl-list/2001-12/msg00651.html

The result is the same text, but in which every character is preceded
by the "|" character.

The benefit of using the function f:str-map() is more obvious, when
the single characters of the string have to be transformed in a more
complex way, which excludes other straightforward solutions -- for
example there were examples in the past (with f:str-zipWith()) of
implementing bitwise operations



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play

Current Thread