0

i have the xml output

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="/topic/get-all.xslt"?>
<List>
    <item>
        <id>8541915a-9098-4d10-bf80-5fbc9a5800af</id>
        <name>TestTopfdic4</name>
        <modifiedDate>2019-12-18T12:37:42.718</modifiedDate>
    </item>
    <item>
        <id>55bc34e6-5cd2-436a-9d37-ceb1052187b0</id>
        <name>TestTopfdic4</name>
        <modifiedDate>2019-12-18T12:40:12.948</modifiedDate>
    </item>
    <item>
        <id>2fee9ce3-1595-4c56-9833-cda03642ad05</id>
        <name>TestTopfdic4</name>
        <modifiedDate>2019-12-18T12:42:15.385</modifiedDate>
    </item>
</List>

And try to tarnsform to html via xslt, I try to select each item and handle it separatly

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/*">
        <html>
            <body>
                <table align="center">
                    <thead>
                        <th>Id</th>
                        <th>Name</th>
                        <th>modified date</th>
                    </thead>
                    <tbody>
                        <xsl:for-each select="List">
                            <tr>
                                <td><xsl:value-of select="item.id"/></td>
                                <td><xsl:value-of select="item.name"/></td>
                                <td><xsl:value-of select="item.modifiedDate"/></td>
                            </tr>
                        </xsl:for-each>
                    </tbody>

                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

But get empty output, what am I doing wrong? Coult you help me please to solve this problem ?

2 Answers 2

1

Your syntax is not XPath syntax. Try:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/List">
        <html>
            <body>
                <table align="center">
                    <thead>
                        <th>Id</th>
                        <th>Name</th>
                        <th>modified date</th>
                    </thead>
                    <tbody>
                        <xsl:for-each select="item">
                            <tr>
                                <td><xsl:value-of select="id"/></td>
                                <td><xsl:value-of select="name"/></td>
                                <td><xsl:value-of select="modifiedDate"/></td>
                            </tr>
                        </xsl:for-each>
                    </tbody>

                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

Comments

0

There's a couple of mistakes here. Firstly, <xsl:for-each select="List"/> iterates over multiple List elements. You only have one List element and you are trying to iterate over its children: that would be <xsl:for-each select="List/*"/>. But then the context item would have to be the root (document) node, not the List element, so you would want match="/" rather than match="/*".

Secondly, you've used "." instead of "/" as your path separator: item.id should be item/id.

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.