Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1 XML file many XLST for a website

Status
Not open for further replies.

lito247

Programmer
May 21, 2004
10
US
Guys,
I am a newbie to xml, we have a client who wanted us to make them a brochure website, but they want it to be flexible enough to accomidate different distributior. Basically the whole website is identical for every distributor of our clients product and the only difference would be the Disctributor company name, logo, phone and email.

I can't quite picture how to put this together, but it would be great if the whole site would work of a single xml file that is linked to different xslt style sheets to fill in the blanks.

This is how my tiny xml file looks...
<distributor>
<company>[OEM]</company>
<logo path=" />
<phone>1-800-000-0000</phone>
<email>email@company.com</email>
</distributor>

I am not exactly sure how to tie this into xslt, point me in the right direction.

Thanks,
Lito
 
...the only difference would be the Disctributor company name, logo, phone and email.

Still believe in the Tooth Fairy, do we? :) Ok, sarcasm aside, they're lying to you. Trust me.

Personally, although others will argue with me on this, I think you should approach this as a database problem rather than an XML/XSL problem. You'll reach an easier, more flexible solution if you treat this as a data-driven Web site with a database on the back end, especially if it grows beyond a trivial stage.
 
Is this data for the brochure going to be static or dynamic? If the data is static and you are the only individuals that update the brochure information, then you could definitely provide the majority of the framework in XML/XSLT. But if the data is supposed to be dynamic, and you want businesses to be able to update their information provided on the brochure, on the fly, then you may want to incorporate a database.

You could build each page with one xslt a two xml files. One xml could contain all the brochure information. Another xml could contain all the different companies. Then one xslt pulls all that information from both files into one transformation. You will most likely want to use a programming language like Java or .Net. I always would recommend transformation on the server-side and sending the users the HTML result.

The code could look like this:

Code:
<distributors>
    <distributor>
        <company>OEM</company>
        <logo path="[URL unfurl="true"]http://"/>[/URL]
        <phone>1-800-000-0000</phone>
        <email>email@nada.com</email>
    </distributor>
    <distributor>
        <company>Nada</company>
        <logo path="[URL unfurl="true"]http://"/>[/URL]
        <phone>1-800-000-0000</phone>
        <email>email@nada.com</email>
    </distributor>
</distributors>

<brochure>
    <paragraph>
        <title>Revolutionizing the industry</title>
        <body>Creating new blah blah blah, that can blah blah blah blah...better than the blah.</body>
    </paragraph>
    <paragraph>
        <title>Contact Us</title>
        <body>We look forward to answering your questions on blah.</body>
    </paragraph>    
</brochure>

<?xml version='1.0' encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:variable name="selectedComp" select="'Nada'"/>
    <xsl:variable name="companies" select="document('distributors.xml')"/>
    <xsl:template match="/">
        <xsl:apply-templates select="$companies/distributors/distributor[company = $selectedComp]"/>
        <xsl:apply-templates select="/brochure"/>
    </xsl:template>
    <xsl:template match="distributor">
        <table>
            <tr>
                <td>
                    <xsl:value-of select="company"/>
                </td>
            </tr>
            <tr>
                <td>
                    <img src="{logo/@path}"/>
                </td>
            </tr>
            <tr>
                <td>
                    <xsl:value-of select="phone"/>
                </td>
            </tr>
            <tr>
                <td>
                    <xsl:value-of select="email"/>
                </td>
            </tr>
        </table>
    </xsl:template>
    <xsl:template match="brochure">
        <xsl:for-each select="paragraph">
            <p>
                <table>
                    <tr>
                        <td>
                            <xsl:value-of select="title"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <xsl:value-of select="body"/>
                        </td>
                    </tr>
                </table>
            </p>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

There are a few ways to implement the code you require. This is just one suggestion.

-jay
 
Thanks for the help,
I ended up making a XML/XSLT set for all the pages. The content is going to be static, except as noted for company specific info. like phone, logo, email, ect. I agree with both of you about using a server side language to make this work better but this is just not an option at this time, since the client chooses to host and administer this on his own servers.

Thanks for the help.
--Lito
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top