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

Re: processing text nodes one character at a time

Subject: Re: processing text nodes one character at a time
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Tue, 26 Sep 2006 18:17:06 -0700
xsl select one character
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

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.