Re: Parameter problem!!

Subject: Re: Parameter problem!!
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2000 20:44:32 +0100
Peter,

>Well I don't think that I am using a parser at all since I am working with
>microsofts visual sudio! I am new to this thing called xlst. It seems however
>that what I am trying to do is to change the xsl template in runtime so to
>speak. I would like in some way to change the valu of a parameter that will
>work as an inout to the xls:if statement in the template. The variable or
>attribut must in some way be possible to pass from an asp page to the template.

To use parameters passed in from an asp page, you have to:
1. pass the parameters from the asp page
2. accept the parameters within the stylesheet
3. use the parameters within the stylesheet

I'm not sure which of these stages you're having problems with.  Ben assumed you were having problems with stage 1, which is passing the parameters into the stylesheet from the asp page.  When he talked about the parser you were using, he meant what are you using to make the stylesheet run, to call the stylesheet from the asp page.  It sounds as though it's MSXML, which is Microsoft's XML/XSLT processor - you should make sure you have the most recent version from their web site.  Ben offered to help you more with the asp side of things, and I don't know much about it, so I'll concentrate on giving you a hand with the other two stages.

For Stage 2, accepting the parameters within the stylesheet, you need to declare them using xsl:param elements at the top level of the stylesheet (immediate children of the xsl:stylesheet element):

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  ...
  <xsl:param name="foo" />
  ...
</xsl:stylesheet>

You can specify a default value for the parameter either as its content or as the value of the 'select' attribute, if you want.  Usually stylesheet parameter values are strings, so be aware, if you use the 'select' attribute, that you have to put quotes around the default value, otherwise it will interpret it as an XPath, so use:

  <xsl:param name="foo" select="'bar'" />

rather than:

  <xsl:param name="foo" select="bar" />

which will try to set it to the value of any 'bar' elements that are lying around.

As far as using the parameter is concerned (Stage 3), you can refer to a particular parameter using '$parameter-name', so '$foo' in the case above.  If you want to test its value to see what to generate, for example, you can use:

  <xsl:if test="$foo = 'bar'">
    <!-- some content -->
  </xsl:if>

I hope this helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


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


Current Thread