メイン コンテンツをスキップする

XSLスタイルシートを使ってXMLからHTMLに変換

このシナリオでは、XSLスタイルシートを使ってXMLデータをHTMLドキュメントに変換する2つのコンポーネントのジョブについて説明します。また、作成されたHTMLドキュメントのヘッダーの背景色を変更できるよう、XSLスタイルシートの変換パラメーターも定義します。

Talendでサポートされているテクノロジーの詳細は、Talendコンポーネントをご覧ください。

このシナリオではcustomers.xmlcustomers.xslという2つの入力ファイルが使われます。

customers.xmlのコンテンツは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<Customers>
    <Customer RegisterTime="2001-01-17 06:26:40.000">
        <Name>
            <id>1</id>
            <CustomerName>Griffith Paving and Sealcoatin</CustomerName>
        </Name>
        <Address>
            <CustomerAddress>talend@apres91</CustomerAddress>
            <idState>2</idState>
        </Address>
        <Revenue>
            <Sum1>67852</Sum1>
        </Revenue>
    </Customer>
    <Customer RegisterTime="2002-06-07 09:40:00.000">
        <Name>
            <id>2</id>
            <CustomerName>Bill's Dive Shop</CustomerName>
        </Name>
        <Address>
            <CustomerAddress>511 Maple Ave. Apt. 1B</CustomerAddress>
            <idState>3</idState>
        </Address>
        <Revenue>
            <Sum1>88792</Sum1>
        </Revenue>
    </Customer>
    <Customer RegisterTime="1987-02-23 17:33:20.000">
        <Name>
            <id>3</id>
            <CustomerName>Glenn Oaks Office Supplies</CustomerName>
        </Name>
        <Address>
            <CustomerAddress>1859 Green Bay Rd.</CustomerAddress>
            <idState>2</idState>
        </Address>
        <Revenue>
            <Sum1>1225.</Sum1>
        </Revenue>
    </Customer>
    <Customer RegisterTime="1992-04-28 23:26:40.000">
        <Name>
            <id>4</id>
            <CustomerName>DBN Bank</CustomerName>
        </Name>
        <Address>
            <CustomerAddress>456 Grossman Ln.</CustomerAddress>
            <idState>3</idState>
        </Address>
        <Revenue>
            <Sum1>64493</Sum1>
        </Revenue>
    </Customer>
    <Customer RegisterTime="1999-04-26 23:26:44.000">
        <Name>
            <id>5</id>
            <CustomerName>Facelift Kitchen and Bath</CustomerName>
        </Name>
        <Address>
            <CustomerAddress>220 Vine Ave.</CustomerAddress>
            <idState>10</idState>
        </Address>
        <Revenue>
            <Sum1>888888</Sum1>
        </Revenue>
    </Customer>
</Customers>
customers.xslのコンテンツは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:param name="bgcolor"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>Customers</h2>
                <table border="1">
                    <tr bgcolor="{$bgcolor}">
                        <th>ID</th>
                        <th>Name</th>
                        <th>Address</th>
                    </tr>
                    <xsl:for-each select="Customers/Customer">
                        <tr>
                            <td><xsl:value-of select="Name/id"/></td>
                            <td><xsl:value-of select="Name/CustomerName"/></td>
                            <td><xsl:value-of select="Address/CustomerAddress"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

このページは役に立ちましたか?

このページまたはコンテンツに、タイポ、ステップの省略、技術的エラーなどの問題が見つかった場合は、お知らせください。改善に役立たせていただきます。