RE: effective use of parameters and/or named templates?

Subject: RE: effective use of parameters and/or named templates?
From: "Maxime Levesque" <maximel@xxxxxxxxxxxxxx>
Date: Tue, 27 Jul 1999 09:25:32 -0700

  You probably want to use :

<xsl:template match=" a matching expression ">

  ... ...
  <xsl:call-template name="aName" select='.'>
        <xsl:param name="nameOfParam1">value of param 1</xsl:param>
	  <xsl:param name="nameOfParam2">value of param 2</xsl:param>
  </xsl:call-template>
</xsl:template>


  <!-- this template will print param1 and param2 -->
  <!-- notice that it has no match attribute ... ->

  <xsl:template name="aName">
      <xsl:param-variable name="nameOfParam1"/>
      <xsl:param-variable name="nameOfParam2/>

      <xsl:value-of select="$nameOfParam1"/>
      <xsl:value-of select="$nameOfParam2"/>

  </xsl:template>



> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of Linda van den Brink
> Sent: Tuesday, July 27, 1999 3:31 AM
> To: Xsl-List (E-mail)
> Cc: Barry van Oven
> Subject: effective use of parameters and/or named templates?
>
>
> Hi all,
>
> I'm working on an XSL stylesheet which I think would benefit from
> the use of
> parameters and/or named templates. However, having no programming
> background
> whatsoever, I'm having difficulty in finding out if and how to use them.
>
> I have an XML document containing a very long list of software items, each
> item having child elements like name, description, version, etc,
> and one or
> more categories, like this:
>
> <software>
> 	<item>
> 		<name>Amaya for Windows NT</name>
> 		<version>2.1</version>
> 		<desc>Amaya is the name of the World Wide Consortium's own
> test-bed browser/authoring tool and is used to demonstrate and
> test many of
> the new developments in Web protocols and data formats. Given the
> very fast
> moving nature of Web technology, Amaya has a central role to play. It is
> versatile and extensible: new features can be easily added.</desc>
> 		<size>4.17 MB</size>
> 		<url>amaya.exe</url>
> 		<home>http://www.w3.org/Amaya/</home>
> 		<license>Freeware</license>
> 		<install>Install</install>
> 		<category>web browser</category>
> 	</item>
> </software>
>
> My aim is to transform this list to a whole series of HTML pages in which
> the items are arranged by category. I couldn't arrange the XML document by
> category, however, because one item can be in more than one category.
>
> What I know how to do is write a template that matches software, and has a
> whole series of xsl:for-each elements, one for each category, like this
> (fragment):
> 		<xsl:for-each select="item[category='web browser']">
> 			<xsl:sort select="name"/>
> 			<xsl:element name="div">
> 				<xsl:attribute name="id">item<xsl:number
> value="position()" format="1"/></xsl:attribute>
> 				<xsl:attribute
> name="class">newsItem</xsl:attribute>
> 				<h4><xsl:apply-templates
> select="name"/>&#160;<xsl:apply-templates select="version"/></h4>
> 				<p><xsl:apply-templates select="desc"/></p>
> 			</xsl:element>
> 		</xsl:for-each>
> 		<xsl:for-each select="item[category='browser add on']">
> 			<xsl:sort select="name"/>
> 			<xsl:element name="div">
> 				<xsl:attribute name="id">item<xsl:number
> value="position()" format="1"/></xsl:attribute>
> 				<xsl:attribute
> name="class">newsItem</xsl:attribute>
> 				<h4><xsl:apply-templates
> select="name"/>&#160;<xsl:apply-templates select="version"/></h4>
> 				<p><xsl:apply-templates select="desc"/></p>
> 			</xsl:element>
> 		</xsl:for-each>
> etc....
>
> Which allows me to process the entire list of software items.
> However, since
> there are a lot of categories, it seems to me I would be repeating a lot.
> (everything between the xsl:for-each elements)
>
> So, my question is how can I reduce the number of lines in my
> stylesheet by
> using xsl:param or named templates (or are there other solutions as well)?
> The nicest thing (as far as I can imagine) would be if the
> stylesheet could
> find all the different categories and then apply a standard
> template once to
> all of them.
>
> I would appreciate any help and explanations!
>
>
> Linda van den Brink
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Current Thread