'Select multiple tag values using the xsl select attribute

i'm using the following XML block of code :

 <w:tc>
    <w:tcPr>
       <w:tcW w:w="7300" />
       <w:gridSpan w:val="3" />
       <w:tcBorders>
          <w:top w:val="nil" />
          <w:left w:val="nil" />
          <w:bottom w:val="nil" />
          <w:right w:val="nil" />
       </w:tcBorders>
    </w:tcPr>
    <w:p>
       <w:r>
          <w:rPr>
             <w:sz w:val="20" />
          </w:rPr>
          <w:t>TEST 1</w:t>
       </w:r>
    </w:p>
    <w:p>
       <w:r>
          <w:rPr>
             <w:sz w:val="20" />
          </w:rPr>
          <w:t>TEST 2</w:t>
       </w:r>
    </w:p>
 </w:tc>

Right now, the following line just returns the value TEST 1

<xsl:variable name="runContents" select="substring-after(substring-before($cellData, '</w:t>'),'<w:t>')"/>

How is it possible to select all the <w:t> values at once. If possible with a carriage return between. Thank you for your help.



Solution 1:[1]

This is possible with XSLT-2.0 or above:

<xsl:value-of select="/w:c/w:p/w:r/w:t" separator="&#xa;" />

or shorter, respectively, with

<xsl:value-of select="//w:t" separator="&#xa;" />

The output is

TEST 1
TEST 2

Instead of using xsl:value-of to output the values, you can select all of them with an xsl:variable. But for output, you'd have to use the approach above.


If you have only XSLT-1.0 available, you'd have to put it in a for-each loop to output all of the values:

<xsl:variable name="elemName" select="/w:c/w:p/w:r/w:t" />
<xsl:for-each select="$elemName">
    <xsl:value-of select="." />
    <xsl:if test="position() != last()"><xsl:text>&#xa;</xsl:text></xsl:if>
</xsl:for-each>

The output is the same.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zx485