Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2005, 10:37 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Store Literal Value in Variable/Parameter

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:

Code:
<?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"/>

<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;subLeftnav={subLeftnav}#38;tableStatus={tableStatus}#38;sortBy={sortBy}#38;sortType={sortType}#38;sortOrder={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>
    </xsl:if>
</xsl:for-each>
The resulting value is this:
{$mainpath}page={@id}&dir={dir_code}&subdir1={subd ir1_code}&subdir2={subdir2_code}&subLeftnav={subLe ftnav}&tableStatus={tableStatus}&sortBy={sortBy}&s ortType={sortType}&sortOrder={sortOrder}

...but I want it to be this:
http://SERVER/DIRECTORY/index.aspx?p...rder=ascending

I've also tried placing the variable within the template itself, and changing it to a parameter like this:
Code:
<xsl:param name="fullpath" select="{$mainpath}page={@id}#38;dir={dir_code}#38;subdir1={subdir1_code}#38;subdir2={subdir2_code}#38;subLeftnav={subLeftnav}#38;tableStatus={tableStatus}#38;sortBy={sortBy}#38;sortType={sortType}#38;sortOrder={sortOrder}" />
...but the result was exactly the same. How can I accomplish this? Thanks for any help.

KWilliams
 
Old August 25th, 2005, 12:06 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

One way is to use the concat function:
Code:
<xsl:param name="fullpath" select="concat($mainpath, 'page=', @id)"/>
concat takes an "unlimited" number of arguments, I've just show the first part here. This will need to be in a part of your stylesheet where the variable mainpath and the attribute id are in scope though, they won't necessarily be available outside a template body.

--

Joe (Microsoft MVP - XML)
 
Old August 25th, 2005, 01:18 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow, thank you for the great response, as it worked great. I did have to make a little change for it to pull the id attribute from the specified document's node like this:
<xsl:param name="fullpath" select="concat($mainpath, 'page=', $internal_links/internal_links/page/@id)" />

...but it works wonderfully. This step will save me A LOT of hassle, and I really appreciate your help:)

KWilliams
 
Old August 29th, 2005, 02:10 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello again,

I have another question about this setup...hope it's not a problem:)

I noticed that you stated that using this variable/parameter method has to be within a in scope within the template body. And that's how I've set it up so far:
Code:
...<xsl:template match="/">
        <xsl:for-each select="$internal_links/internal_links/page">
            <xsl:if test="@id = 'home'">
                <xsl:param name="fullpath" select="concat($mainpath, 'page=', @id, '#38;dir=', dir_code, '#38;subdir1=', subdir1_code)" />
                <a href="{$fullpath}">Home Page Data</a>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>...
But since every page on my site will have the same 8 querystring variables with varying values in its path, I'd love to create a way to store a generic form of that path so that it doesn't need to be within each method, like this:
Code:
<?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"/>
<xsl:variable name="mainpath">http://SERVER/DIRECTORY/index.aspx?</xsl:variable>
<xsl:variable name="internal_links" select="document('internal_links.xml')" />
<xsl:param name="fullpath" select="concat($mainpath, 'page=', @id, '#38;dir=', dir_code, '#38;subdir1=', subdir1_code)" />
    <xsl:template match="/">
        <xsl:for-each                 select="$internal_links/internal_links/page">
            <xsl:if test="@id = 'home'">
                <a href="{$fullpath}">Home Page Data</a>
            </xsl:if>
        </xsl:for-each>

        <xsl:for-each select="$internal_links/internal_links/page">
            <xsl:if test="@id = 'formsdocs'">
                <a href="{$fullpath}">Forms #38; Documents Data</a>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
So if anyone knows of a way to accomplish this, I'd love to know of it. If it's not possible...too bad. Thanks for any help.

KWilliams
 
Old August 31st, 2005, 02:17 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's okay if @id and etc. are available, where does it come from, the main XML of the one brought in with the document function? If the latter then you just need to qualify the path more:
Code:
$internal_links/<some path parts here>/@id
--

Joe (Microsoft MVP - XML)
 
Old August 31st, 2005, 08:52 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm kind of confused by your reply. The @id attribute that is called is part of the <xsl:for-each method, like this: <xsl:for-each select="$internal_links/internal_links/page">. @id is the attribute value of the page node. But I'm not having a problem with that setup if I use a generic <xsl:value-of method. It's only when I try to pull a variable's generic value that I get this issue. I've also tried using a xsl:param instead, but it didn't change anything.

I want to know if I could have a variable at the top of the document and outside of the template body that contains a generic value in its select property. I then want to call that variable's generic select property in within different methods (i.e. <xsl:for-each...). But when I use the method that I included, it does pull that variable's value, but it doesn't pull the actual values from the XML doc.

Every path for all pages within our site are going to use the exact same path & querystring:
http://SERVER/DIRECTORY/index.aspx?p...ORTORDER_VALUE

...but the values will come from the different methods that contain the $fullpath variable.

For instance:
<xsl:variable name="mainpath">http://SERVER/DIRECTORY/index.aspx?</xsl:variable>
<xsl:param name="fullpath" select="concat($mainpath, 'page=', @id, '#38;dir=', dir_code, '#38;subdir1=', subdir1_code, '#38;subdir2', subdir2_code, '#38;subleftnav=', subleftnav, '#38;modules=', modules, '#38;sortby=', sortby, '#38;sorttype=', sorttype, '#38;sortorder=', sortorder)" />
    <xsl:template match="/">
        <xsl:for-each select="$internal_links/internal_links/page">
                <xsl:if test="@id = 'home'">
                    <a class="small" href="{$fullpath}">Home</a>
                </xsl:if>
                <xsl:if test="@id = 'formsdocs'">
                    <a class="small" href="{$fullpath}">Forms #38; Documents</a>
                </xsl:if>
        </xsl:for-each>
</xsl:template match>

results in:
<a href="http://SERVER/DIRECTORY/index.aspx?page=&dir=&subdir1=&subdir2=&subleftnav =&modules=&sortby=&sorttype=&sortorder=">Home</a>
<a href="http://SERVER/DIRECTORY/index.aspx?page=&dir=&subdir1=&subdir2=&subleftnav =&modules=&sortby=&sorttype=&sortorder=">Forms #38; Documents</a>

...but I want it to result in:
<a href="http://SERVER/DIRECTORY/index.aspx?page=home&dir=&subdir1=&subdir2=&sublef tnav=&modules=true&sortby=&sorttype=&sortorder=">H ome</a>
<a href="http://SERVER/DIRECTORY/index.aspx?page=formsdocs&dir=onlineservices&subdi r1=formsdocs&subdir2=&subleftnav=&modules=true&sor tby=title&sorttype=text&sortorder=ascending">Forms #38; Documents</a>

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
@ parameter1 not a parameter in store procedure shoakat ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2007 04:32 AM
How to store ntext or text value to local variable ramk_1978 SQL Server 2000 3 September 14th, 2005 07:59 PM
How to store single value in variable? sacred21 Classic ASP Basics 1 December 29th, 2004 05:25 AM
Pass parameter to store procedure & Crystal Report quinn Classic ASP Professional 0 March 10th, 2004 02:16 PM
Store a value to a variable until user quits Acces Sharq Access VBA 7 January 7th, 2004 10:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.