Click to See Complete Forum and Search --> : How to Store Literal Value in Variable/Parameter


kwilliams
08-24-2005, 11:41 AM
I'm creating a dynamic site that uses one ASP.NET page (index.aspx) to pull data from XML/XSLT/CSS to create webpages dynamically. Some of the properties are passed through the QueryString.

I'm wanting to store a literal value within a default variable which is to be placed within every XSLT stylesheet for my dynamic site. I want this because I'd like to keep uniformity for a full path that will be called from several pages within the same page.

For my example page, here are the results for the QueryString values:
page=formsdocs
dir=onlineservices
subdir1=formsdocs
subdir2=N/A
subLeftnav=true
tableStatus=true
sortBy=title
sortType=text
sortOrder=ascending

...and the value for the $mainpath variable is: http://SERVER/DIRECTORY/index.aspx.

This is what I have so far:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<!-- Default variables -->
<xsl:variable name="mainpath">http://SERVER/DIRECTORY/index.aspx?</xsl:variable>
<xsl:variable name="fullpath">{$mainpath}page={@id}#38;dir={dir_code}#38;subdir1={subdir1_code}#38;subdir2={subdir2_code}#38;subLe ftnav={subLeftnav}#38;tableStatus={tableStatus}#38;sortBy={sortBy}#38;sortType={sortType}#38;sortOrd er={sortOrder}</xsl:variable>
<xsl:variable name="il_onlineservices" select="document('http://SERVER/DIRECTORY/SUBDIR/docs/xml/internal_links.xml')" />
<xsl:template match="/">
<xsl:for-each select="$il_onlineservices/internal_links/page">
<xsl:if test="@id = 'formsdocs'">
<a class="small" href="{$fullpath}">more Forms #38; Documents...</a><!-- <<<THIS IS WHERE I WANT IT DISPLAYED WITHIN THE HREF PROPERTY -->
</xsl:if>
</xsl:for-each>


The resulting value is this:
{$mainpath}page={@id}&dir={dir_code}&subdir1={subdir1_code}&subdir2={subdir2_code}&subLeftnav={subLeftnav}&tableStatus={tableStatus}&sortBy={sortBy}&sortType={sortType}&sortOrder={sortOrder}

...but I want it to be this:
http://SERVER/DIRECTORY/index.aspx?page=formsdocs&dir=onlineservices&subdir1=formsdocs&subdir2=&subLeftnav=true&tableStatus=true&sortBy=title&sortType=text&sortOrder=ascending

I've also tried placing the variable within the template itself, and changing it to a parameter like this:

<xsl:param name="fullpath" select="{$mainpath}page={@id}#38;dir={dir_code}#38;subdir1={subdir1_code}#38;subdir2={subdir2_code}#38;subLe ftnav={subLeftnav}#38;tableStatus={tableStatus}#38;sortBy={sortBy}#38;sortType={sortType}#38;sortOrd er={sortOrder}" />

...but the result was exactly the same. How can I accomplish this? Thanks for any help.

sheila
08-25-2005, 02:13 PM
At the risk of getting into an overly long-winded explanation ;) , have you tried:

<xsl:variable name="fullpath">
<xsl:value-of select="$mainpath" />
<xsl:text>page=</xsl:text><xsl:value-of select="@id" />
<xsl:text>#38;dir=</xsl:text><xsl:value-of select="$dir_code" />
<xsl:text>#38;subdir1=</xsl:text><xsl:value-of select="$subdir1_code" />
<xsl:text>#38;subdir2=</xsl:text><xsl:value-of select="$subdir2_code" />
<xsl:text>#38;subLeftnav=</xsl:text><xsl:value-of select="$subLeftnav" />
<xsl:text>#38;tableStatus=</xsl:text><xsl:value-of select="$tableStatus" />
<xsl:text>#38;sortBy=</xsl:text><xsl:value-of select="$sortBy" />
<xsl:text>#38;sortType=</xsl:text><xsl:value-of select="$sortType" />
<xsl:text>#38;sortOrder=</xsl:text><xsl:value-of select="$sortOrder" />
</xsl:variable>

You said that you're passing the querystring values through to the stylesheet so I've just assumed that it was a mistake that you didn't call "subdir1_code" as "$subdir1_code", etc. If not, then presumably "subdir1_code", etc. are elements in your XML and you'll need to remove the dollar signs that I've added.

You can probably get away with not putting the plain text bits in <xsl:text /> tags.

kwilliams
08-25-2005, 02:44 PM
Hello sheila,

Your solution worked great. I also received another reply on the P2P Wrox site with the following alternative solution using the concat() method:
<xsl:variable name="fullpath" select="concat($mainpath, 'page=', @id, '&dir=', dir_code, '&subdir1=', subdir1_code, '&subdir2', subdir2_code, '&subLeftnav=', subLeftnav, '&sortBy=', sortBy, '&sortType=', sortType, '&sortOrder=', sortOrder)" />

...and this solution also works great. Thanks for your help:)