K
K
Kornushenkov2019-05-02 14:45:54
XSL & XSLT
Kornushenkov, 2019-05-02 14:45:54

How to parse string in XSLT by delimiter?

Good day!
There is an XML document with unloading of goods. Each card has a tag in which the size is indicated in the form of Width/Height/Length how to split it using the separator / through XSLT and write the values ​​​​in separate new tags.
From:

<cart>
...
...
...
<dimensions>15.2/44/13.5</dimensions>
...
</cart>

Do this way:
<cart>
...
...
...
<width>15.2</width>
<height>44</height>
<length>13.5</length>
...
</cart>

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Fov, 2019-05-02
@Kornushenkov

XML

<cart>
  <dimensions>15.2/44/13.5</dimensions>
</cart>

XSLt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/cart">
    <div>
      <xsl:text>Ширина: </xsl:text>
      <xsl:value-of select="substring-before(dimensions, '/')"/>
    </div>
    <div>
      <xsl:text>Высота:</xsl:text>
      <xsl:value-of select="substring-before(substring-after(dimensions, '/'), '/')"/>
    </div>
    <div>
      <xsl:text>Глубина:</xsl:text>
      <xsl:value-of select="substring-after(substring-after(dimensions, '/'), '/')"/>
    </div>
  </xsl:template>
</xsl:stylesheet>

result
<div>Ширина: 15.2</div>
<div>Высота:44</div>
<div>Глубина:13.5</div>

It?

O
overdd, 2019-10-17
@overdd

More kosher would be to use the tokenize function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question