xsl-list
[Top] [All Lists]

[xsl] Getting a <TableRow> where <Cell> doesn't contain a colspan attribute

2009-06-25 12:51:03
Hello everyone,

Hope somebody can help me with the correct phrasing for this test. It must be within xslt 1.0

In the following xml structure i want to check for a <TableRow> where the child element <Cell> doesn't contain the attribute 'ColSpan'. The reason that i need a <TableRow> without colspan cells is to calculate with an for-each command the number of columns within the table.

xml sample:

            <Paragraph Pstyle="Plattetekst">
                <Text Cstyle="[No character style]">
                    <Table>
                        <TableHeader>
                            <TableRow>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">header</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">header</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">header</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">header</Text>
                                    </Paragraph>
                                </Cell>
                            </TableRow>
                        </TableHeader>
                        <TableBody>
                            <TableRow>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">veld1</Text>
                                    </Paragraph>
                                </Cell>
<Cell ColSpan="2" Width="50" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">veld2</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">veld4</Text>
                                    </Paragraph>
                                </Cell>
                            </TableRow>
                            <TableRow>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">1</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">2</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">3</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">4</Text>
                                    </Paragraph>
                                </Cell>
                            </TableRow>
                            <TableRow>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">i</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">ii</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">iii</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">iv</Text>
                                    </Paragraph>
                                </Cell>
                            </TableRow>
                            <TableRow>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">a</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">b</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">c</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">d</Text>
                                    </Paragraph>
                                </Cell>
                            </TableRow>
                        </TableBody>
                        <TableFooter>
                            <TableRow>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">footer</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">footer</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">footer</Text>
                                    </Paragraph>
                                </Cell>
<Cell Width="25" TopBorder="3" RightBorder="3" BottomBorder="3" LeftBorder="3" VAlign="top">
                                    <Paragraph Pstyle="Plattetekst">
<Text Cstyle="[No character style]">footer</Text>
                                    </Paragraph>
                                </Cell>
                            </TableRow>
                        </TableFooter>
                    </Table>
                </Text>
            </Paragraph>

What i got sofar is:

    <!-- Match 'Table'. -->
    <xsl:template match="Table">
        <informaltable>
            <xsl:choose>
<!-- Check if attribute border (top, right, bottom, left) is defined. -->
                <!-- Otherwise leave attribute out. -->
                <xsl:when test="descendant::Cell/@TopBorder">
                    <xsl:attribute name="border">
<xsl:value-of select="descendant::Cell/ @TopBorder"/>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="descendant::Cell/@RightBorder">
                    <xsl:attribute name="border">
<xsl:value-of select="descendant::Cell/ @RightBorder"/>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="descendant::Cell/@BottomBorder">
                    <xsl:attribute name="border">
<xsl:value-of select="descendant::Cell/ @BottomBorder"/>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="descendant::Cell/@LeftBorder">
                    <xsl:attribute name="border">
<xsl:value-of select="descendant::Cell/ @LeftBorder"/>
                    </xsl:attribute>
                </xsl:when>
            </xsl:choose>

            <xsl:choose>
<xsl:when test="descendant::TableRow/ not(Cell[(_at_)ColSpan])"> <== this is wrong phrasing i know, but can't find the correct one.
                    <xsl:for-each select="descendant::TableRow/Cell">
                        <col/>
                    </xsl:for-each>
                </xsl:when>
            </xsl:choose>

            <xsl:apply-templates/>
        </informaltable>
    </xsl:template>

Regards,

Casper Voortman

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>