Royeh
Royeh

Reputation: 443

Have no output as html view

I have an XML file which reads a relates XSLT file and then I could see output as HTML in web browser. There should be table where the first column is the name of components' node in XML file and the second column is the description of components But after some changes I could not have any desired output. It shows only an empty table as is shown in following pic.

enter image description here

Would you please help me?

My XML file:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<Summary>
    <test name="test">
        <xml_name name="ABC">
            <version num="104">
                <component name="APPS">
                    <componenet_ver>104</componenet_ver>
                </component>
            <component name="Ner">
                <componenet_ver>1.0</componenet_ver>
                </component>
                <component name="HUNE">
                    <componenet_ver>003</componenet_ver>
                </component>
                <component name="FADA">
                    <componenet_ver>107</componenet_ver>
                </component>
                <component name="VEDA">
                    <componenet_ver>8.8</componenet_ver>
                </component>
            </version>
        </xml_name>
    </test>
</Summary>

and XSLT file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="Summary/test">
    <html>
        <body>
            <table>
                <tr bgcolor="Peru">
                    <th>Components</th>
                    <th>Versions</th>
                </tr>
                <xsl:for-each select="//component">
                    <xsl:variable name="CompomName" select="@name"/>
                    <xsl:variable name="VerName" select="description"/>
                    <tr>
                       <td bgcolor="aqua" name = "{$CompomName}"> </td>
                       <td bgcolor="aqua" name = "{$VerName}"> </td>
                    </tr>
                </xsl:for-each>                                 
            </table>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

Upvotes: 0

Views: 49

Answers (3)

gp.
gp.

Reputation: 8225

couple of corrections:

1/ You need to write values as text of elements which are missing.

Corrected:

<td bgcolor="aqua" name = "{$CompomName}">
    <xsl:value-of select="$CompomName" />
</td>
<td bgcolor="aqua" name = "{$VerName}">
    <xsl:value-of select="$VerName" /> 
</td>

2/ for variable VerName, you are selecting "description" element which does not exist. What you might be intending is to select "component_ver" element as below:

<xsl:variable name="VerName" select="componenet_ver"/>

Try these 2 and it would work.

enter image description here

Upvotes: 0

Gottfried Lesigang
Gottfried Lesigang

Reputation: 67301

Try this (corrected missing end tags):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="Summary/test">
    <html>
        <body>
            <table>
                <tr bgcolor="Peru">
                    <th>Components</th>
                    <th>Versions</th>
                    </tr>
                        <xsl:for-each select="//component">
                        <xsl:variable name="CompomName" select="@name"/>
                        <xsl:variable name="VerName" select="./componenet_ver"/>
                    <tr>
                    <td bgcolor="aqua" name = "{$CompomName}"><xsl:value-of select="$CompomName"/></td>
                    <td bgcolor="aqua" name = "{$VerName}"><xsl:value-of select="$VerName"/></td>  
</tr>                                 
</xsl:for-each>
            </table>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

Upvotes: 1

michael.hor257k
michael.hor257k

Reputation: 116982

Your stylesheet is not well-formed: you are missing the closing tags for the second <tr> as well as for the <xsl:for-each> and </xsl:stylesheet> instructions.


Added:

It shows only an empty table.

The table is empty because the table cells have no content (other than spaces). Try it this way?

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="Summary/test">
    <html>
        <body>
            <table>
                <tr bgcolor="Peru">
                    <th>Components</th>
                    <th>Versions</th>
                </tr>
                <xsl:for-each select="//component">
                    <xsl:variable name="CompomName" select="@name"/>
                    <xsl:variable name="VerName" select="componenet_ver"/>
                    <tr>
                       <td bgcolor="aqua" name="{$CompomName}">
                            <xsl:value-of select="$CompomName"/>
                       </td>
                       <td bgcolor="aqua" name="{$VerName}"> 
                            <xsl:value-of select="$VerName"/>
                       </td>
                    </tr>
                </xsl:for-each>                                 
            </table>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

Not sure if you really need to name the cells, I have left that in.

Note that your <xsl:variable name="VerName" select="description"/> does not select anything.

Upvotes: 2

Related Questions