Was wondering if anybody could help me with this, its a bit of an odd one!
I want to split a value, in to its separate elements. So 123, would become 123.
Somethings like...
<xsl:variable name="value" select="123">
<xsl:variable name="valueTransform" select="magic-transform($123)" />
which would give an output like
<number>
<node>1</node>
<node>2</node>
<node>3</node>
</number>
The rational behind this, is splitting numbers so they can each be assigned a css-class ready for image replacement.
So the number becomes a pretty image, but its still accessible!
Hi Laurence, I'm not completely sure know what your input is - a 2-digit week number you want to split into 2 separate digits, or a string of 2-digit weeknumbers you want to split into separate weeknumbers, or ...
Splitting a Number
Hi guys,
Was wondering if anybody could help me with this, its a bit of an odd one!
I want to split a value, in to its separate elements. So 123, would become 123.
Somethings like...
The rational behind this, is splitting numbers so they can each be assigned a css-class ready for image replacement.
So the number becomes a pretty image, but its still accessible!
Any pointers much appreciated! Laurie
Hi Laurence,
Do you have control over the value "123"? Could you comma-separate them? "1,2,3"?
If so, then you could use umbraco.library:Split() to do what you need.
Cheers, Lee.
No, sadly not its a two digit week number. /L (so ranges from 0 - 52)
Hi Laurence, I'm not completely sure know what your input is - a 2-digit week number you want to split into 2 separate digits, or a string of 2-digit weeknumbers you want to split into separate weeknumbers, or ...
Anyway, you could consider using the xslt substring function (http://msdn.microsoft.com/en-us/library/ms256054.aspx)
>Tommy
Laurence...
can you use to grab specific indexes of the string?
Hi Laurence,
If you're in a position to use an XSLT extension, try this:
Works the same say as umbraco.library.Split(), but turns the string into a Char array.
Cheers, Lee.
To confirm, this is an example...
INPUT = 42
I want to split this into 4 and 2.
So I can output
<span class="digit4">4</span>
<span class="digit2">2</span>
Thanks for the responses so far! I will look into this more, but its Friday I'm off out for drinks and good times! :) Hope you are too :)
Have a lovely weekend, will try some of the above tomorrow :) Laurie
Hi Laurence,
This recursive template will do the trick:
- and a god weekend to you too :-)
/Chriztian
Hi Laurence, you can use the EXSLT string function split (or tokenize) with an empty string, which will separate the string into each character see here: http://www.exslt.org/str/functions/split/str.split.html
In use it would be:
which would give the following node set in the $valueTransform variable:
Not sure if the umbraco.library:Split function works in the same way, but the EXSLT one certainly claims to.
I do have to say that Chriztian's solution will do exactly what you are asking for,
/Josh
Thanks for all the replies on this thread.
Really like the solutions suggested with particular note too Chriztian's and Josh's.
Many thanks! Laurie
is working on a reply...