H
H
hitry_lis2018-03-27 23:06:28
XSL & XSLT
hitry_lis, 2018-03-27 23:06:28

How to split a string into characters?

There is a node with attributes

<ФИО Фамилия="Алексеев" Имя="Алексей" Отчество="Алексеевич"></ФИО>

when called, I will get a string Alexey, the question is how to break it into characters so that in the end I get something like this structure in the xsl file
<tr >
 <td>А</td>
<td>л</td>
<td>е</td>
<td>к</td>
<td>с</td>
<td>е</td>
<td>й</td>
 </tr>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2018-07-15
@Roman-Fov

If it's easy to do, then you can use exslt
XML:
XSLt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:str="http://exslt.org/strings" extension-element-prefixes="str">

  <xsl:template match="/">
    <xsl:apply-templates select="ФИО/@Имя"/>
  </xsl:template>

  <xsl:template match="ФИО/@Имя">
    <tr>
      <xsl:for-each select="str:tokenize(string(.), '')">
        <td>
          <xsl:value-of select="." />
        </td>
      </xsl:for-each>
    </tr>
  </xsl:template>
</xsl:stylesheet>

result:
<tr><td>А</td><td>л</td><td>е</td><td>к</td><td>с</td><td>е</td><td>й</td></tr>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question