Re: [xsl] Variable construction: Afterthought...

Subject: Re: [xsl] Variable construction: Afterthought...
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Wed, 21 Sep 2005 10:13:21 -0500
On 9/21/05, Aaron Johnson <Aaron2.Johnson@xxxxxxxxx> wrote:
> There is an existing document which I cannot change. In the document there
> is a line of code...
> .....If you have any queries, please contact your <a target="_blank"
>  href="{$helpUrl}">Faculty Office</a> without delay....
> ...which outputs a line of text with a url in it.
> I understand that the {$helpUrl} is a variable.
> The document that contains this variable, another .xsl,  can be changed and
> is as follows:
> <xsl:param name="helpFac"/>
>   <xsl:variable name="helpUrl">
>     <xsl:choose>
>       <xsl:when test="$helpFac !=
> e-of select="$helpFac"/></xsl:when>
> herwise>
>     </xsl:choose>
>   </xsl:variable>
> I want to get rid of the "helpFac" parameter as well as the choose
> and replace the whole thing with a single url.

Aaaahh, that makes a bit more sense.  Do you really need to?  It
allows for templates calling that one to "override" the default.  But
if you really always want it to be one url you're on the right track.
The stuff about external documents and the like is just a red herring.

> I thought that
> <xsl:variable name="helpUrl"
> select=""/>
> ...would suffice.

You just need quotation marks since it's not a path location but a string.

> I can't test it because I don't have any xml to run
> against it....sounds stupid I know but I'm still fairly new to xsl...I'm
> trying to think logically.

To create a test case here you don't need much.

Create an xml file called foo.xml with <root>foo</root>.  That should
be more than enough to make most xml parsers happy.

Then you can test it against a stylesheet like

<xsl:stylesheet version = "1.0"
   xmlns:xsl = "";>
<xsl:output method="xml"/>

<xsl:variable name="url" select="''" />

<xsl:template match="/">
  <a href="{$url}">Test</a>

with your favorite XSLT processor.  If you're a newbie I highly highly
recommend downloading an XSLT processor and playing around with
running scripts by hand before trying to use the browser

Jon Gorman

Current Thread