A
A
Anton Golubkov2018-04-05 08:31:08
HTML
Anton Golubkov, 2018-04-05 08:31:08

How to parse string in XSLT transformation?

Good afternoon! There is an XML document and it is necessary to make its XSLT transformation. The trouble is that the string must be parsed into table cells - one letter in one cell, in order to form a semblance of a printing form, that is

<Документ КНД="1111053" ДатаДок="16.01.2012" КодНО="7601">

should look something like this
<tr>
<td>КНД</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>5</td>
<td>3</td>
</tr>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2018-04-05
@Gwynbleidd44

You can implement this using substring .
XML document:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="docstyle.xsl"?>

<Документы>
    <Документ КНД='1102345' ДатаДок="16.01.2012" КодНО="7601" />
    <Документ КНД='1111053' ДатаДок="12.12.2016" КодНО="7601" />
</Документы>

XSL Schema (docstyle.xsl)
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns="http://www.w3.org/1999/xhtml">
    <xsl:output method="xml" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

    <xsl:template match="Документы/Документ">
        <tr>
            <td><xsl:value-of select="@ДатаДок"/></td>
            <td><xsl:value-of select='substring(@КНД,1,1)'/></td>
            <td><xsl:value-of select='substring(@КНД,2,1)'/></td>
            <td><xsl:value-of select='substring(@КНД,3,1)'/></td>
            <td><xsl:value-of select='substring(@КНД,4,1)'/></td>
            <td><xsl:value-of select='substring(@КНД,5,1)'/></td>
            <td><xsl:value-of select='substring(@КНД,6,1)'/></td>
        </tr>
    </xsl:template>
</xsl:stylesheet>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question