471,075 Members | 926 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

<a href> and xsl

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
Feb 5 '07 #1
8 4289
* 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 · mailto:bj****@hoehrmann.de · 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/
Feb 5 '07 #2
<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 <aelement, then add an attribute that
has a computed value.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 5 '07 #3
In article <45c757a5$1@kcnews01>,
Joseph Kesselman <ke************@comcast.netwrote:
<a target="_blank">
<xsl:attribute name="href">
<xsl:apply-templates select="key[text()='Location']"
mode="getValue" /"

... in other words, create the <aelement, 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
Feb 5 '07 #4
Larry wrote:
In article <45c757a5$1@kcnews01>,
Joseph Kesselman <ke************@comcast.netwrote:
> <a target="_blank">
<xsl:attribute name="href">
<xsl:apply-templates select="key[text()='Location']"
mode="getValue" /"

... in other words, create the <aelement, 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
Feb 5 '07 #5
In article <52*************@mid.individual.net>,
Peter Flynn <pe********@m.silmaril.iewrote:
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
Feb 5 '07 #6
In article <do********************************@reader2.news.t in.it>,
Larry <do**********@got.itwrote:

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>
Feb 5 '07 #7
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
Feb 6 '07 #8
Larry wrote:
In article <do********************************@reader2.news.t in.it>,
Larry <do**********@got.itwrote

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
Feb 6 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gregor Horvath | last post: by
2 posts views Thread by Donald Firesmith | last post: by
6 posts views Thread by snacktime | last post: by
5 posts views Thread by specjal | last post: by
1 post views Thread by rn5a | last post: by
3 posts views Thread by ajay2552 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.