Is this possible from an XSL?

P

Prabh

Hello all,
I'm a newbie to the world of XML, XSL stylesheets and transformation
etc. and wonder if the following is possible?

I have an XML file of the following sort and I want to HTML-ize it
using an XSL.

XML:

==========================================================
<target name="one">
<task>
<message> Some Message Text1 </message>
<message> Some Message Text2 </message>
</task>

<task>
<message> Some Message Text3 </message>
</task>
</target>

<target name="two">
<task>
<message> Some Message Text1 </message>
</task>
</target>

and so on.
=========================================================

After transformation, in my .html file, I'd like to create a top-area
of just the target names and clicking on the links would get me to
their details (i.e., the tasks and messages info) somewhere down
below.

Something along the lines...

<a href="#TargetOneInfo"> Target One </a>
<a href="#TargetTwoInfo"> Target Two </a>
..
..
..
<a name="TargetOne"> Target One Details </a>
<a name="TargetTwo"> Target Two Details </a>
and so on.

Is it possible to achieve this in XSL?
How do I specify in XSL to collect all 'targets' and put the href tags
around them and similarly put the name tags around the details
section?
Could someone please give me some pointers on how to go about doing
this?

Thanks for your time,
Prabh
 
J

Joris Gillis

It's off course possible with XSL. here's one way to do it.

The stylesheet you need looks like this:
(some additional styling can be added with CSS)

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:eek:utput method="html"/>

<xsl:template match="/">
<html><body>
<p title="targets">
<xsl:for-each select="//target">
<a href="#Task{@name}">Target <xsl:value-of select="@name"/></a><br/>
</xsl:for-each>
</p>
<p title="details">
<xsl:for-each select="//target">
<a name="#Task{@name}">
Target <xsl:value-of select="@name"/> Details</a>
<ul><xsl:apply-templates/></ul>
</xsl:for-each>
</p>
</body></html>
</xsl:template>

<xsl:template match="task">
<li>Task <xsl:value-of select="position()"/>
<ul><xsl:apply-templates/></ul>
</li>
</xsl:template>

<xsl:template match="message">
<li><xsl:value-of select="."/></li>
</xsl:template>

</xsl:stylesheet>

Hope this helps,

Joris Gillis
 

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

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top