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> <a href="#b2">2</a> <a
href="#b3">3</a> <a href="#b4">4</a> </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/