xslt: create link from name

Felix Natter

Usenet Archive
Joined
Apr 21, 2000
Messages
88
Reaction score
0
hi,

I have glossary-entries (<entry name="...">...</entry>) whose names include 8bit-characters and spaces and each entry must be reachable by (relative) html-links.

I want to avoid having to specify both a name and an id for linking for each glossary term (if possible), so I'd like to generate links (urls) from the names with some kind of algorithm.

I need (at least) a function that creates a valid url from a name (i.e. "x y" => "x%20y").

thanks,
 

Felix Natter

Usenet Archive
Joined
Apr 21, 2000
Messages
88
Reaction score
0
Michael Hill said:
I think you may be looking for <xsl:element> and/or <xsl:attribute> . look at them.

No, I'm looking for a function/algorithm/idea to convert i.e. "this Topic" to "this%20topic" or similar. Without this function I'd have to do this:

<entry name="Formular zurücksetzen" id="formularzuruecksetzen"> </entry> <entry name="Faktura" id="faktura"> </entry> ... and have some redundancy (@id) which is what I try to avoid. A function like "url(@name)" (which would "urlify" @name, " "=>%20 etc.) would be sufficient (if there's no better solution).

thanks in advance,
 

FC

Usenet Archive
Joined
May 14, 2003
Messages
41
Reaction score
0
I suppose that's the purpose of generate-id function.
Have a look at it and see if it suits your needs.

Bye,
Flavio
 

Felix Natter

Usenet Archive
Joined
Apr 21, 2000
Messages
88
Reaction score
0
FC said:
I suppose that's the purpose of generate-id function.
Have a look at it and see if it suits your needs.

It won't work because it is not required that the ids
stay the same across stylesheet invocations (and for a glossary the name-anchors need to stay the same)

From XSLT by Doug Tidwell:
"[...] All of tomorrow's calls to generate-id will generate the same ID but that ID might not be the one generated today."
 

Felix Natter

Usenet Archive
Joined
Apr 21, 2000
Messages
88
Reaction score
0
Felix Natter said:
No, I'm looking for a function/algorithm/idea to convert i.e. "this Topic" to "this%20topic" or similar. Without this function I'd have to do this:

<entry name="Formular zurücksetzen" id="formularzuruecksetzen"> </entry> <entry name="Faktura" id="faktura"> </entry> ... and have some redundancy (@id) which is what I try to avoid. A function like "url(@name)" (which would "urlify" @name, " "=>%20 etc.) would be sufficient (if there's no better solution).

I found an extension which does this: encode-uri
(http://www.exslt.org/str/)
 

Frank-Ralph Reiser

Usenet Archive
Joined
Jul 31, 2003
Messages
2
Reaction score
0
Felix Natter schrieb:

>I found an extension which does this: encode-uri
>(http://www.exslt.org/str/)

Is there a better solution? It's a bit tedious to use
i.e. #Formular%20zur%C3%BCcksetzen as a link.

You could use e.g. the XPath core function "translate" to change any special char. For Example translate(@name,' ᅵᅵᅵᅵᅵᅵᅵ','_aouAOUs'). Or look at http://www.informatik.hu-berlin.de/~obecker/Lehre/SS2002/XML/07g-xslt.html

There are several example templates, one to replace any occurances of a string within another.

Frank-Ralph Reiser
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top