Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > <a href> and xsl

Reply
Thread Tools

<a href> and xsl

 
 
Larry
Guest
Posts: n/a
 
      02-05-2007
Hi,

I'm trying to get the following working but I'm at a loss and dont
know what is wrong with it:

<div class="name">
<a href=" <xsl:apply-templates select="key[text()='Location']"
mode="getValue" /> " target="_blank">
<xsl:apply-templates select="key[text()='Name']" mode="getValue" />
<xsl:text> </xsl:text>
</a>
</div>

any help?

thansks
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      02-05-2007
* Larry wrote in comp.text.xml:
>Hi,
>
> I'm trying to get the following working but I'm at a loss and dont
>know what is wrong with it:
>
><div class="name">
> <a href=" <xsl:apply-templates select="key[text()='Location']"
>mode="getValue" /> " target="_blank">
> <xsl:apply-templates select="key[text()='Name']" mode="getValue" />
> <xsl:text> </xsl:text>
> </a>
></div>


You cannot use elements in attribute values, you have to use the special
xsl:attribute element or attribute value templates, refer to the XSLT
1.0 specification for details:

http://www.w3.org/TR/xslt#creating-attributes
http://www.w3.org/TR/xslt#dt-attribute-value-template

Only the former will allow you to use apply-templates.
--
Björn Höhrmann · (E-Mail Removed) · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-05-2007
> <a href=" <xsl:apply-templates select="key[text()='Location']"
> mode="getValue" /> " target="_blank">


You can't issue an apply-templates call from inside an attribute value. Try:

<a target="_blank">
<xsl:attribute name="href">
<xsl:apply-templates select="key[text()='Location']"
mode="getValue" /> "

.... in other words, create the <a> element, then add an attribute that
has a computed value.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      02-05-2007
In article <45c757a5$1@kcnews01>,
Joseph Kesselman <(E-Mail Removed)> wrote:

> <a target="_blank">
> <xsl:attribute name="href">
> <xsl:apply-templates select="key[text()='Location']"
> mode="getValue" /> "
>
> ... in other words, create the <a> element, then add an attribute that
> has a computed value.


ok, I got it. But now I'm having some trouble making a substitution,
here's some code:

<xsl:template match="dict">
<div>
<div class="name">
<a target="_blank">
<xsl:attribute name="href">
<xsl:apply-templates select="key[text()='Location']"
mode="getAsUri"/>
</xsl:attribute>
<xsl:apply-templates select="key[text()='Name']" mode="getValue" />
<xsl:text> </xsl:text>
</a>
</div>
</div>
</xsl:template>

<xsl:template match="key" mode="getValue">
<xsl:value-of select="following-sibling::*[1]" />
</xsl:template>

<xsl:template match="key" mode="getAsUri">
<xsl:variable name="txt">
<xsl:apply-templates select="." mode="getValue" />
</xsl:variable>
<xsl:text>http://127.0.0.1:8000/</xsl:text>
<xsl:value-of select="substring-after($txt,'file:///')"
disable-output-escaping="yes" />
</xsl:template>

It should turn:

file:///Users/etc...

to:

http://127.0.0.1:8000/Users/etc...

sadly, it doesn't work properly as I only get http://127.0.0.1:8000/
without the /Users/etc... part

I can't work out what is wrong with the code

any help?

thanks
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      02-05-2007
Larry wrote:
> In article <45c757a5$1@kcnews01>,
> Joseph Kesselman <(E-Mail Removed)> wrote:
>
>> <a target="_blank">
>> <xsl:attribute name="href">
>> <xsl:apply-templates select="key[text()='Location']"
>> mode="getValue" /> "
>>
>> ... in other words, create the <a> element, then add an attribute that
>> has a computed value.

>
> ok, I got it. But now I'm having some trouble making a substitution,
> here's some code:
>
> <xsl:template match="dict">
> <div>
> <div class="name">
> <a target="_blank">
> <xsl:attribute name="href">
> <xsl:apply-templates select="key[text()='Location']" mode="getAsUri"/>


That will select all child elements of dict called key, whose (implicit)
first stretch of unmarked character data content is equal to "Location".
The template for key will then provide a value starting with the quoted
http method, IP address and port, plus the delocalised value of the text
content of the first element following the key, omitting to escape the
ampersands. Is this what you meant? Presumably the element following
such a key element does indeed contain a URI.

> </xsl:attribute>
> <xsl:apply-templates select="key[text()='Name']" mode="getValue" />
> <xsl:text> </xsl:text>
> </a>
> </div>
> </div>
> </xsl:template>
>
> <xsl:template match="key" mode="getValue">
> <xsl:value-of select="following-sibling::*[1]" />
> </xsl:template>
>
> <xsl:template match="key" mode="getAsUri">
> <xsl:variable name="txt">
> <xsl:apply-templates select="." mode="getValue" />
> </xsl:variable>
> <xsl:text>http://127.0.0.1:8000/</xsl:text>
> <xsl:value-of select="substring-after($txt,'file:///')"
> disable-output-escaping="yes" />
> </xsl:template>
>
> It should turn:
>
> file:///Users/etc...
>
> to:
>
> http://127.0.0.1:8000/Users/etc...
>
> sadly, it doesn't work properly as I only get http://127.0.0.1:8000/
> without the /Users/etc... part
>
> I can't work out what is wrong with the code


If you provided us with some sample data so that we didn't have to work
blind it would help...

///Peter
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      02-05-2007
In article <(E-Mail Removed)>,
Peter Flynn <(E-Mail Removed)> wrote:

> If you provided us with some sample data so that we didn't have to work
> blind it would help...


http://www.theartofweb.net/xml/wow.xml

now, try and move your mouse over several links, you get the same:
http://127.0.0.1:8000/

instead, I'd like it to be like:
http://127.0.0.1:8000/value_of_'Location'_without_this_at_the_beginning_ f
ile:///

take a look at the file, its standalone kind of

thanks
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      02-05-2007
In article <(E-Mail Removed)>,
Larry <(E-Mail Removed)> wrote:


> take a look at the file, its standalone kind of


help!! I just want to transform this:

<tag>file:///Users/</tag>

to this:

<tag>http://127.0.0.1:8000/Users</tag>
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      02-06-2007
> help!! I just want to transform this:
> <tag>file:///Users/</tag>
> to this:
> <tag>http://127.0.0.1:8000/Users</tag>


If you want the URI to be relative to where the document was loaded
from, why not just use a relative URI in the first place:

<tag>/Users</tag>

That makes this the browser's problem... and any browser ought to handle
it properly.



--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      02-06-2007
Larry wrote:
> In article <(E-Mail Removed)>,
> Larry <(E-Mail Removed)> wrote
>
> http://www.theartofweb.net/xml/wow.xml


Not Found
The requested URL /xml/wow.xml was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use
an ErrorDocument to handle the request.

>> take a look at the file, its standalone kind of

>
> help!! I just want to transform this:
>
> <tag>file:///Users/</tag>
>
> to this:
>
> <tag>http://127.0.0.1:8000/Users</tag>


<xsl:value-of select="concat('http://127.0.0.1:8000/',
substring-after(tag,'file:///'))"/>

///Peter
--
XML FAQ: http://xml.silmaril.ie
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
xsl:import and xsl:apply_import David Carlisle XML 5 12-16-2004 02:44 PM
XSLT question related to <xsl:template> and <xsl:apply-templates> Vijay singh XML 1 11-04-2004 03:42 PM
Difference between xsl:param and xsl:variable? Karsten Weinert XML 3 07-05-2004 04:58 PM
Three question which is not yet answered clearly and correct so far !! challenging question in xsl and also in xsl fo Philip Meyer XML 0 11-30-2003 04:42 PM



Advertisments