Delmitting / Splitting Attribute Values in XSLT

I need to split an attribute value and I need to do this in a loop.

For example

my xml file:

<att1 val="8/10/12"> </att1>

I need to iterate over val and split into 8,10,12 or say 8,10,12,14 or 10,12,14,16. I cannot change the xml to something more sensible like child nodes for each value.

I can think of an algorithmn with

string = substring-before(string, substring)
string = substring-after(string, substring)

I ask for the string before and after, so the first time I get 8 & 10/12. Then I do it again and I get 10 & 12.
Voila!, but I need to do it in a loop (so I can deal with 8/10/12/16/18, and the only looping I can find is for-each! does any one clever have any ideas?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Kentusha,

You can accomplish this using recursion:

To demonstrate it, I use your XML source:
  <att1 val="8/10/12"/>

Here is the XSL:
1. Main template:
<xsl:template match="/">
  <xsl:call-template name="returnStringBefore">
    <xsl:with-param name="myString" select="//att1/@val"/>

2. Template you call recursively:
<xsl:template name="returnStringBefore">
  <xsl:param name="myString"/>
      <xsl:when test="substring-after($myString, '/') != ''">
        <xsl:value-of select="substring-before($myString, '/')"/>    
        <xsl:call-template name="returnStringBefore">
          <xsl:with-param name="myString" select="substring-after($myString, '/')"/>
        <xsl:value-of select="$myString" />


The output would look like this:

Hope this helps.  Good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kentushaAuthor Commented:
Thanks! That worked a treat.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.