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 November 3rd, 2003, 10:28 AM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTML Links

I would like to create a link in XSLT, my problem is I have not figured out how to include variables in the link address. For Example:

<a href="test.php?city=<xsl:value-of select="City"/>">test</a>

 
Old November 3rd, 2003, 11:08 AM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try using curly braces:

<a href="test.php?city={$City}">test</a>

...sam

 
Old November 3rd, 2003, 11:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

or you can use xsl:element and xsl:attribute, like this:
<xsl:element name="a">
  <xsl:attribute name="href">test.php?city=<xsl:value-of select="City"/></xsl:attribute>
  test
</xsl:element>
 
Old November 3rd, 2003, 11:42 AM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by pgtips
 or you can use xsl:element and xsl:attribute, like this:
<xsl:element name="a">
<xsl:attribute name="href">test.php?city=<xsl:value-of select="City"/></xsl:attribute>
test
</xsl:element>
I have tried both methods but I'm not getting a well formed file because my link is actually like this test.php?city={$City}&state={$State}

It appears that the second = sign creates a problem.
Any help is appreciated.
Thank you
Pete

 
Old November 3rd, 2003, 12:14 PM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try escaping the & before state:

<a href="test.php?city={$City}&amp;state={$State}">te st</a>

...sam

 
Old November 3rd, 2003, 12:24 PM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now it is well formed but I still get errors. Now I get;
href="http://www.mapquest.com/maps/map.adp?city={$City}&amp;state={$State}"

 
Old November 3rd, 2003, 12:25 PM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default


highlighted with the error "Invalid variable referenceError in XPath expression, Invalid variable reference"

Any ideas?

Thank you

 
Old November 3rd, 2003, 01:00 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There is no need for a dollar sign unless City is an xsl:variable. If it's just an XPath expression use without the dollar.

Joe (MVP - xml)
 
Old November 3rd, 2003, 01:58 PM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As usual, I think Joe hit it on the nose. Are "City" and "State" in the XML file you are transforming, or are you creating variables within your stylesheet with names "City" and "State"?

For example, I get the following output with my examples below:

<a href="test.php?city=VarCity&amp;state=VarState">Va rTest</a>
<a href="test.php?city=XPathCity&amp;state=XPathSate" >XPathTest</a>

Example XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [
    <!ELEMENT test (#PCDATA | City | State)*>
    <!ELEMENT City (#PCDATA)>
    <!ELEMENT State (#PCDATA)>
]>
<test>
    <City>XPathCity</City>
    <State>XPathSate</State>
</test>

Example XSL (I use saxon):

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon">

    <xsl:output method="html"/>

    <xsl:variable name="City" select="'VarCity'"/>
    <xsl:variable name="State" select="'VarState'"/>

    <xsl:template match="test">

        <a href="test.php?city={$City}&amp;state={$State}">Va rTest</a>
        <a href="test.php?city={City}&amp;state={State}">XPat hTest</a>

    </xsl:template>

</xsl:stylesheet>

Hope that helps,

...sam






Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove orphaned html elements from html string pauliehaha C# 2008 aka C# 3.0 2 June 30th, 2008 09:40 AM
Only some images must have links brettdalldorf ASP.NET 1.0 and 1.1 Basics 0 August 7th, 2005 08:49 AM
Can you preload child html files to 1parent html? bekim Javascript How-To 4 January 22nd, 2005 04:17 PM
Table Links samdavis HTML Code Clinic 2 November 30th, 2004 06:38 AM
Broken Links kilika Forum and Wrox.com Feedback 1 September 15th, 2003 10:01 AM





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