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.

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.