[xsl] same layout on many XSL files but different content

Subject: [xsl] same layout on many XSL files but different content
From: "jim" <xsl@xxxxxxxxxxxxxxxxx>
Date: Tue, 1 Jul 2003 02:37:33 -0700
I have just moved from using Server Side Includes (SSI) text files for the
product content of my site to an XML database and XSL files for each product
page. The following is working, but I know it could be more efficiently
written.

1. My first question is if I want to change the layout, I don't want to have
to change each XSL file for each product. I've been unsuccessful at trying
to use either xsl:import or xsl:include.

2. My second question is should I really be using "for-each" followed by "if
match" if I only want to display 1 product's information per page?

HERE IS ONE OF MY MANY XSL FILES - THEY ARE ALL THE SAME EXCEPT THE
CATEGORY_ID CHANGES ON EACH ONE:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>
<xsl:template match="/">
  <xsl:for-each select="catalogue/product">
    <xsl:if match=".[category_id='1.02']">

      <!--THE FOLLOWING IS USED ON MULTIPLE XSL FILES AND I WANT TO CHANGE
IT ONCE-->
      <p class="heading"><xsl:value-of select="item_name"/> [<xsl:value-of
select="category_id"/>]</p>
      <p class="description"><xsl:value-of select="description"/></p>
      <p class="details">Colours: <xsl:value-of select="colours"/><br />
      Fabric: <xsl:value-of select="fabric"/><br />
      Sizes: <xsl:value-of select="sizes"/><br />
      Retail Price: CDN <xsl:value-of select="price_cdn"/> | USD
<xsl:value-of select="price_usd"/><br />
      Shipping: <xsl:value-of select="shipping"/></p>
      <p class="verysmall">More Views: <a
href="javascript:swapProdImg(0);">front</a> | <a
href="javascript:swapProdImg(1);">side</a> | <a
href="javascript:swapProdImg(2);">back</a> | <a
href="javascript:swapProdImg(3);">detail</a><br />
      Matching Items: <a><xsl:attribute
name="href">/retail/group/<xsl:value-of select="group_number"
/>/index.html</xsl:attribute><xsl:value-of select="merch_group" /></a><br />
      Browse By Category: <a><xsl:attribute
name="href">/retail/category/<xsl:value-of select="category_number"
/>/index.html</xsl:attribute><xsl:value-of select="category" /></a></p>
      <!--THE FOLLOWING IS USED ON MULTIPLE XSL FILES AND I WANT TO CHANGE
IT ONCE-->
    </xsl:if>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>


HERE IS PART OF MY XML FILE FOR REFERENCE:

<catalogue>
	<product>
		<item_name>Baby Doll Top</item_name>
		<group_id>101</group_id>
		<category_id>1.01</category_id>
		<price_cdn>$50</price_cdn>
		<price_usd>$35</price_usd>
		<sizes>4-6-8-10-12</sizes>
		<fabric>100% cotton</fabric>
		<colours>latte; wine</colours>
		<merch_group>The Denim Collection</merch_group>
		<group_number>100</group_number>
		<category_number>1.00</category_number>
		<category>shirts+tops</category>
		<page>tops1</page>
		<shipping>ships in two weeks</shipping>
		<description>The baby doll top has an elastic gathered neckline, empire
style waist and leg of mutton sleeves.</description>
	</product>
	<product>
      ...
      </product>
</catalogue>

Thanks!

Jim



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread