1

I have an html table with the following definition

    <table>
    <tr> 
        <th>Order ID</th> 
        <th>Item ID</th> 
        <th>Participant ID</th> 
        <th>Status</th> 
        <th>Shipping Provider</th> 
        <th>Tracking Number</th> 
        <th>Shipped Date</th> 
        <th>Shipping Method</th>
    </tr> 
    <tr> 
        <td align="center"> Ch_H907</td> 
        <td align="center"> 907</td> 
        <td align="center"> DXM09902</td> 
        <td align="center"> Shipped</td> 
        <td align="center"> USPS</td> 
        <td align="center"> </td> 
        <td align="center"> 04/03/2017</td> 
        <td align="center"> Standard Ground</td> 
    </tr> 
    <tr> 
        <td align="center"> Ch_H871</td> 
        <td align="center"> 871</td> 
        <td align="center"> DXM09902</td> 
        <td align="center"> Shipped</td> 
        <td align="center"> USPS</td> 
        <td align="center"> </td> 
        <td align="center"> 04/03/2017</td> 
        <td align="center"> Standard Ground</td> 
    </tr> 
</table>

and an xslt translation definition as follows

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fo="http://www.w3.org/1999/XSL/Format" >
    <xsl:output method="text" omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="//tr">
            <xsl:for-each select="td">
                <xsl:value-of select="concat({.},',')"/>
            </xsl:for-each>
             <xsl:value-of select="concat('&#xA;','')"/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

My desired output should be each <tr> on a separate line but the above translation throws an exception line 9: Required attribute 'select' is missing.

Ayodeji
  • 579
  • 2
  • 8
  • 25

1 Answers1

4

You don't need the curly braces in the concat statement.

Instead of doing this...

<xsl:value-of select="concat({.},',')"/>

Do this...

<xsl:value-of select="concat(.,',')"/>

Curly braces are properly used as Attribute Value Templates

Note that you might want to re-jig your code to avoid writing an extra comma at the end of each line.

    <xsl:for-each select="//tr">
        <xsl:for-each select="td">
            <xsl:if test="position() > 1">,</xsl:if>
            <xsl:value-of select="."/>
        </xsl:for-each>
         <xsl:text>&#xA;</xsl:text>
    </xsl:for-each>
Tim C
  • 70,053
  • 14
  • 74
  • 93