[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
amaya template

  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.