3
votes

I am using XSL to convert a HTML document to XML. How to concatenate the text in all the descendant nodes of a particular type with a separator?As an example I have a table node and it has several td nodes as descendants, how to combine the text in all those td elements?For the below input and using ',' as separator, the output should be 'value1,value2,value3,value4'

<table>
    <tr>
        <td>value1</td>
    </tr>
    <tr>
        <td>
            <table>
                <tr>
                    <td>value2</td>
                    <td>value3</td>
                </tr>
                <tr>
                    <td>value4</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
1
@αƞjiβ XSL style sheetthemanwhosoldtheworld

1 Answers

4
votes

Try:

<xsl:value-of select="//td[text()]" separator=","/>

or:

<xsl:value-of select="string-join(//td[text()],',')"/>

string-join() is particularly useful in AVT's.