This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Transformation from XML to Table Rows
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: Transformation from XML to Table Rows
- From: Estefan27 at aol dot com
- Date: Mon, 04 Dec 2000 17:30:50 EST
- Reply-To: xsl-list at mulberrytech dot com
Hi everyone i have been making progress on the XML solution I refered to before. Here is the progress thus far. the everything in the first template match works to perfection. (<xsl:template match="/">)
Within the first template. I'm using a for each instruction. that displays rows.
now within each loop i want it to list all the child sub_topics.
It's not doing that . if anyone could help with this issue that would be great.
stephen
once again the xml document structure looks like this.
<root>
<topic id="1">
<topic_name>topic name</topic_name>
<sub_topic id="1">subtopicname</sub_topic>
<sub_topic id="2">subtopicname</sub_topic>
<sub_topic id="3">subtopicname</sub_topic>
</topic>
<topic id="2">
<topic_name>topic name</topic_name>
<sub_topic id="4">subtopicname</sub_topic>
<sub_topic id="5">subtopicname</sub_topic>
<sub_topic id="6">subtopicname</sub_topic>
</topic>
.
.
.
</root>
AND Below is the XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<BODY bgcolor="white" text="#666666" >
<table width="700px" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<xsl:for-each select="channel_list/topic">
<td align="left" valign="absbottom"><span class="channelname">
<xsl:element name="a">
<xsl:attribute name="href">
/channel.asp?catid=<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="topic_name"/>
<hr noshade="noshade" color="#EBEBEB" align="left" width="200px" />
<xsl:if test="position() mod 3 = 0">
<xsl:element name="tr">
</xsl:element>
</xsl:if>
</xsl:element>
</span></td>
</xsl:for-each>
</tr>
</table>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="topic" mode="sit">
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<xsl:for-each select="topic/sub_topic">
<span class="channeltopic">
<xsl:element name="a">
<xsl:attribute name="href">
/channel.asp?catid=<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="sub_topic" />
</xsl:element>
</span>
</xsl:for-each>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
In a message dated Mon, 4 Dec 2000 4:53:49 PM Eastern Standard Time, Estefan27@aol.com writes:
<< Greetings;
I have an xml document with the following structure:
<root>
<topic id="1">
<topic_name>topic name</topic_name>
<sub_topic id="1">subtopicname</sub_topic>
<sub_topic id="2">subtopicname</sub_topic>
<sub_topic id="3">subtopicname</sub_topic>
</topic>
<topic id="2">
<topic_name>topic name</topic_name>
<sub_topic id="4">subtopicname</sub_topic>
<sub_topic id="5">subtopicname</sub_topic>
<sub_topic id="6">subtopicname</sub_topic>
</topic>
.
.
.
</root>
Can someone please show me how to make an XSLTransformation that will:
--Transform the topic into html rows. 3 topics to row.
(i want it flexible so that i can later change the xsl to 4 per row.
therefore i wish to use something like
<xsl:if test="position() mod 3 = 0">
</tr><tr> <!--naturally this gives an error-->
</xsl:if>
)
all the sub_topics must be presented below each corresponding topic name.
Therefore I'm thinking about something along the lines of the following. (
I could be way off. if someone could help that would be great.
<xsl:template match="/">
<table>
<tr>
<xsl:for-each select="root/topic">
<td><xsl:apply-templates select="displaytopic" />
</td>
<xsl:for-each>
</tr>
</table>
</xsl:template>
<xsl:template match="displaytopic">
<xsl:element name="a">
<xsl:attribute name="href">
/anasppage.asp?id=<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="topic_name" />
</xsl:element>
<xsl:apply-templates select="display_related_sub_topic" />
</xsl:template>
<xsl:template match="display_related_sub_topic">
<xsl:element name="a">
<xsl:attribute name="href">
/anasppage.asp?id=<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="sub_topic" />
</xsl:element>
<xsl:apply-templates select="sub_topic" />
</xsl:template>
all guidance would be greatly appreciated.
s
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list