Return To Web Portfolio >

XML With Perl: XSL Source

Sample of two XSL stylesheets used to transform the XML data into different HTML forms.


<?xml version="1.0"?>
<xsl:stylesheet
    default-space="preserve"
    indent-result="yes"
    xmlns:xsl="http://www.w3.org/TR/WD-xsl"
    xmlns="http://www.w3.org/TR/REC-html40" 
    result-ns="">

    <xsl:template match="*" priority="-1">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="text()">
        <xsl:value-of/>
    </xsl:template>

    <xsl:template match="/">
    <HTML>
        <HEAD>
            <TITLE>Amazon List</TITLE>
            <STYLE TYPE="text/css">
            <![CDATA[
            
            BODY,P,TD,UL,LI,CENTER { 
                            font-family: Helvetica, Arial, sans-serif; 
            }
            ]]>
            </STYLE>

        </HEAD>
        <BODY bgcolor="#FFFFFF">
        <FONT FACE="Helvetica, Arial, sans-serif">
            <xsl:for-each select="/amazon/subjects/subject">
                <FONT color="#000080"><B><xsl:value-of select="@value"/></B></FONT><br />
                <UL>
                    <xsl:for-each select="item">
                        <xsl:value-of select="title"/><xsl:entity-ref name="nbsp"/><xsl:entity-ref name="nbsp"/><xsl:entity-ref name="nbsp"/>
                        <FONT color="#400080">ASIN <xsl:value-of select="@asin" /></FONT>
                        -<FONT color="#400080"> <xsl:value-of select="@type" /></FONT>
                        <xsl:if test="image">- <FONT color="#005500">image</FONT></xsl:if>
                        <br />
                    </xsl:for-each>
                </UL>
                <br /><br />
            </xsl:for-each>
        </FONT>
        </BODY>
    </HTML>
    </xsl:template>
    

</xsl:stylesheet>


<?xml version="1.0"?>
<xsl:stylesheet
    default-space="preserve"
    indent-result="yes"
    xmlns:xsl="http://www.w3.org/TR/WD-xsl"
    xmlns="http://www.w3.org/TR/REC-html40" 
    result-ns="">

    <xsl:template match="*" priority="-1">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="text()">
        <xsl:value-of/>
    </xsl:template>
    
    <xsl:template match="item">
        <xsl:value-of select="title"/><xsl:entity-ref name="nbsp"/><xsl:entity-ref name="nbsp"/><xsl:entity-ref name="nbsp"/>
        <FONT color="#400080">ASIN <xsl:value-of select="@asin" /></FONT>
        -<FONT color="#400080"> <xsl:value-of select="@type" /></FONT>
        <xsl:if test="image">- <FONT color="#005500">image</FONT></xsl:if>
        <br />
    </xsl:template>
    
</xsl:stylesheet>


Return To Web Portfolio >