473,320 Members | 1,825 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.

Creating links with xsl from xml

Hello,

I want to transform a xml to html with xsl which is not this big
problem. But when I want to create a link with informations of the xml
it doesn't work. To illustrate the problem here an example:

link_example.xml

<booklist>
<book>
<id>1</id>
<title>blabla</title>
</book>
<book>
<id>2</id>
<title>blblblblbla</title>
</book>
</booklist>

The output should look like this. There are a list of links which
reference down to the titles in the same document:
Booklist: 1(as a link) 2(as link)

1 blabla
2 blblblblbla
<a href="{id}"><value-of select=".">..... didn't work. I don't know what
to do. Could someone help?

Greetings

Markus

Jul 20 '05 #1
1 3901


schilde wrote:

I want to transform a xml to html with xsl which is not this big
problem. But when I want to create a link with informations of the xml
it doesn't work. To illustrate the problem here an example:

link_example.xml

<booklist>
<book>
<id>1</id>
<title>blabla</title>
</book>
<book>
<id>2</id>
<title>blblblblbla</title>
</book>
</booklist>

The output should look like this. There are a list of links which
reference down to the titles in the same document:
Booklist: 1(as a link) 2(as link)

1 blabla
2 blblblblbla


If I understand you correctly you want to process the <book> elements
twice, once to generate the list with links, once to generate the
detailed list with book titles. One way to do that is template with
modes so that an element can be processed in different modes, here is an
example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="utf-8" indent="yes" />

<xsl:template match="/">
<html>
<head>
<title>A list of books</title>
</head>
<body>
<div>
<p>Booklist:
<xsl:apply-templates select="booklist/book" mode="link" />
</p>
<div>
<ol>
<xsl:apply-templates select="booklist/book" />
</ol>
</div>
</div>
</body>
</html>
</xsl:template>

<xsl:template match="book">
<li id="b{position()}"><xsl:value-of select="title" /></li>
</xsl:template>

<xsl:template match="book" mode="link">
<a href="#b{position()}"><xsl:value-of select="position()" /></a>
<xsl:text> </xsl:text>
</xsl:template>

</xsl:stylesheet>

The resulting HTML is alike

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>A list of books</title>
</head>
<body>
<div>
<p>Booklist:
<a href="#b1">1</a>&nbsp;<a href="#b2">2</a>&nbsp;<a
href="#b3">3</a>&nbsp;<a href="#b4">4</a>&nbsp;</p>
<div>
<ol>
<li id="b1">blabla</li>
<li id="b2">blblblblbla</li>
<li id="b3">Kibology for all</li>
<li id="b4">All for Kibology</li>
</ol>
</div>
</div>
</body>
</html>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CJM | last post by:
I need a vertical menu with maybe 10 links on it. The menu will run the full length of the screen, and will consist of 10 large boxes with large-ish text for the links. These links need to be...
2
by: Joe_Black | last post by:
Hi all, I want to create an MDI app that allows reporting on XML data files downloaded from the equipment that we manufacture, this MDI app will have several default reports but due to the...
1
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
2
by: Stephen Zachmann | last post by:
Ok, I want to have a directory full of pdf files and a page that creates links to them dynamically so that if I add 10 docs or subtract 7 or whatever, they will be added or removed the next time...
6
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. -...
3
by: simon | last post by:
Hello, i'm looking to create an aspx page that is basically a FAQ page i'm not sure if this can be done, but would love some help with suggestions of how to do it another way if this is not...
1
by: simon | last post by:
Hello, i'm looking to create an aspx page that is basically a FAQ page i'm not sure if this can be done, but would love some help with suggestions of how to do it another way if this is not...
4
by: Mario Vázquez | last post by:
Hi, I'm trying to put the links (href attribute of the <a> element) out of my XSLT files, in a XML file, and read it from the stylesheet. I suppose that I have to use the document() function to...
10
by: alanbe | last post by:
I am working on some scripts to help me automate the website creation process. I want to use a template for the whole website and call pages using something like ...
1
by: Remote_User | last post by:
Hi All, .NET 1.1 doesn't support creating symbolic links to files, like in Linux? Can i use C# to make a file point to another file? Thanks.
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: 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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.