473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 4431
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gregor Horvath | last post by:
Hi, Before I reinvent the wheel I`d like to ask if someone has done this before since I did not find an advice at Google. The goal is to create a dynamic Tree View in HTML. Say I have a...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
6
by: snacktime | last post by:
I've searched and searched and have not found a solution to suppress the margin on form or href tags so that there is no space before or after the tag. The only way I have found to do this is to...
5
by: specjal | last post by:
hi in form TEXTAREA i have text like: bla bla http://www.google.com/bla/bla/bla text text text text now how to make from this text like: bla bla text text text text
13
by: tperri | last post by:
I have an HTML table with several fields like this: <A href="Savings.aspx?category=Food"><asp:imagebutton id="imgFood" ImageUrl="images\buttons\btn-food-i.gif"...
1
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub Page_Load(obj As Object, ea As EventArgs) Dim sqlReader As SqlDataReader sqlReader = 'calling a function that returns SqlDataReader ...
3
by: ajaspersonal | last post by:
"i want to change font_style (hyper link<a href...>text</a>) normal to italics.when load a page" this is my problem but that label included in one 'USERCONTROL' This user controls may...
1
by: John | last post by:
Hi var poster="<html><head..... etc .... </html>"; var animal='dog'; The string contains images and text that changes. Originally I wanted to do something like print "<a href=" +...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
8
by: Prisoner at War | last post by:
Another weekend, another project, another problem.... Why should a perfectly fine function work only half-way through when called through onClick in an anchor tag?? The text fade-in script...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.