xsl-list
[Top] [All Lists]

RE: What am I doing wrong?

2004-09-24 07:25:58
Hi Arun,

First of all, your XML is not well-formed, but it may just be a typo: at the
end, <TabularReport> should be </TabularReport>.

Then, you are inserting two <td> elements when the test <xsl:when
test="$row-id = $first-row-id"> is evaluated to true, but only when there is
a child node element named 'AssociateValue'. If it's not there, only one
<td> is generated, but you have a problem when two <td>s are generated, and
on subsequent rows there's only one.

        <xsl:choose>
            <xsl:when test="$row-id = $first-row-id">
                <td>abc<xsl:value-of select="child::GroupValue" /></td>
                <xsl:if test="child::AssociateValue[1]">
                    <td>def<xsl:value-of select="child::AssociateValue[1]"
/></td>
                </xsl:if>
            </xsl:when>
            <xsl:otherwise>
                <td>xxx</td>
            </xsl:otherwise>
        </xsl:choose>

The same problem goes for the next template:

    <xsl:if test="name(preceding-sibling::node()[2]) != 'GroupValue'">
        <xsl:if test="preceding-sibling::AssociateValue[1]">
            <td>ghi<xsl:value-of
select="preceding-sibling::AssociateValue[1]" /></td>
        </xsl:if>
    </xsl:if>

Here, you also add a <td> node element to the output if <AssociateValue>
exist. This will leave you with another empty cell.

In HTML tables, to test, first I always set the border attribute of the
<table> to "1", and all table cells, if you fill them with nothing, fill
them better with something like 'xxx'. Then you know where your logic goes
wrong, and with a debug in for example Xselerator 2.6 you soon know what's
going on.

I do not have the time to help you more, but I do hope you can do something
useful with it. You may be lucky and find that someone else on the list
provides a complete solution. It often happens. 

Cheers,
<prs/>


-----Original Message-----
From: Arun Sinha [mailto:arunsinha666(_at_)hotmail(_dot_)com] 
Sent: Friday, September 24, 2004 4:20 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] What am I doing wrong?


Hi,

Anybody who can point what am i doing wrong? I am not getting the desired
output.

The first line is correct but after that three subsequent lines are not.
The output is missing one '<td></td>' somehow for those three lines.

Thanks in advance.

Arun


Here is the XML file :-


<?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <TabularReport>
<Titles>
    <Title>Supplier</Title>
    <Title>Name</Title>
    <Title>Order No</Title>
    <Title>Order Line</Title>
    <Title>Part</Title>
    <Title>Net Value</Title>
    <Title>Date Requested</Title>
    <Title>Qty Required</Title>
    <Title>Order Status</Title>
    <Title>Exch Rate</Title>
</Titles>

<Group>
    <GroupValue type='alpha'>SUPP1</GroupValue>
    <AssociateValue type='alpha'>Software House</AssociateValue>
    <Group>
        <GroupValue type='alpha'>PO000001</GroupValue>
        <AssociateValue type='numeric'>1</AssociateValue>
        <Row>
            <ColumnValue type='alpha'>SU-1000</ColumnValue>
            <ColumnValue type='numeric'>840</ColumnValue>
            <ColumnValue type='date'>12/06/2000</ColumnValue>
            <ColumnValue type='numeric'>24</ColumnValue>
            <ColumnValue type='alpha'>Released</ColumnValue>
            <ColumnValue type='numeric'>1.00000000</ColumnValue>
        </Row>
        <AssociateValue type='numeric'>2</AssociateValue>
        <Row>
            <ColumnValue type='alpha'>BOX-1</ColumnValue>
            <ColumnValue type='numeric'>0</ColumnValue>
            <ColumnValue type='date'>12/06/2000</ColumnValue>
            <ColumnValue type='numeric'>1</ColumnValue>
            <ColumnValue type='alpha'>Released</ColumnValue>
            <ColumnValue type='numeric'>1.00000000</ColumnValue>
        </Row>
        <AssociateValue type='numeric'>10</AssociateValue>
        <Row>
            <ColumnValue type='alpha'>BOX-2</ColumnValue>
            <ColumnValue type='numeric'>20</ColumnValue>
            <ColumnValue type='date'>31/12/2003</ColumnValue>
            <ColumnValue type='numeric'>20</ColumnValue>
            <ColumnValue type='alpha'>Released</ColumnValue>
            <ColumnValue type='numeric'>1.00000000</ColumnValue>
        </Row>
    </Group>
    <Group>
        <GroupValue type='alpha'>PO000005</GroupValue>
        <AssociateValue type='numeric'>1</AssociateValue>
        <Row>
            <ColumnValue type='alpha'>CD-2000</ColumnValue>
            <ColumnValue type='numeric'>0</ColumnValue>
            <ColumnValue type='date'>12/07/2003</ColumnValue>
            <ColumnValue type='numeric'>10</ColumnValue>
            <ColumnValue type='alpha'>Released</ColumnValue>
            <ColumnValue type='numeric'>1.00000000</ColumnValue>
        </Row>
    </Group>
</Group>
<TabularReport>

Following is the XSL :-

<?xml version="1.0" ?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/TabularReport">

    <html><head><title></title></head><body><left>
    <table>
        <tr>
        <xsl:apply-templates select="Titles/Title" />
        <xsl:apply-templates select=".//Row" />
        </tr>
    </table>
    </left></body></html>

</xsl:template>

<xsl:template match="Row">
    <xsl:variable name="row-id" select="generate-id(.)" />
    <tr>
    <xsl:for-each select="ancestor::Group">
        <xsl:variable name="first-row-id" 
select="generate-id(descendant::Row[1])" />
        <xsl:choose>
            <xsl:when test="$row-id = $first-row-id">
                <td><xsl:value-of select="child::GroupValue" /></td>
                <xsl:if test="child::AssociateValue[1]">
                    <td><xsl:value-of select="child::AssociateValue[1]" 
/></td>
                </xsl:if>
            </xsl:when>
            <xsl:otherwise>
                <td></td>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>

    <xsl:if test="name(preceding-sibling::node()[2]) != 'GroupValue'">
        <xsl:if test="preceding-sibling::AssociateValue[1]">
            <td><xsl:value-of select="preceding-sibling::AssociateValue[1]" 
/></td>
        </xsl:if>
    </xsl:if>
    <xsl:apply-templates select="ColumnValue" />
    </tr>
</xsl:template>

<xsl:template match="Title">
    <td><font color="red" size="2pt"><xsl:value-of select="." /></font></td>
</xsl:template>

<xsl:template match="ColumnValue">
    <td><font color="black" size="2pt"><xsl:value-of select="." 
/></font></td>
</xsl:template>

</xsl:stylesheet>

_________________________________________________________________
The new MSN toolbar! Your shortcut to the internet! 
http://toolbar.msn.co.in/ Access a world of convenience!


--+------------------------------------------------------------------
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>