Hi Folks,
I'm new to xslt transofrmation so need a little help in transforming the following example.

Input:

<Persons>12</Persons>

Output:

<PassengerRPHs ListOfPassengerRPH="1 2"/>

The main thing above is to put a space between digits, 123 -> 1 2 3.
It would be perfect if the transformation also handles 9101112 -> 9 10 11 12

In typical java programming, i know i can tokenize it using some RE and put a space in between and concatenate, but i'm not sure how to do the same in XSLT:(

Any help would be much appreciated.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:template name="split">
  <xsl:param name="str" />
  <xsl:if test="$str">
    <xsl:value-of select="substring($str, 1, 1)" /><xsl:text> </xsl:text>
    <xsl:call-template name="split">
      <xsl:with-param name="str" select="substring($str, 2)" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<xsl:template match="root">
  <xsl:variable name="list">
     <xsl:call-template name="split">
        <xsl:with-param name="str" select="Persons" />
     </xsl:call-template>
  </xsl:variable>
  <xsl:element name="PassengerRPHs">
     <xsl:attribute name="ListOfPassengerRPH">
         <xsl:value-of select="substring($list, 1, string-length($list) - 1)" />
     </xsl:attribute>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.