Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

column for-each

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
I am trying to take the follwing XML

Code:
<?xml version="1.0" encoding="utf-8" ?>
<webmedia>
	<subject name="20040727_OurHouse">
		<images>
			<image 
				id="20040727_OurHouse1" 
				name="20040727_01_OurHouse.jpg" 
				href="images/20040727_OurHouse/" 
				tname="t20040727_OurHouse1" 
				tdir="images/20040727_OurHouse/thumb/" 
			 />
			<image 
				id="20040727_OurHouse2" 
				name="20040727_02_OurHouse.jpg" 
				href="images/20040727_OurHouse/" 
				tname="t20040727_OurHouse2" 
				tdir="images/20040727_OurHouse/thumb/" 
			 />
		</images>
	</subject>
</webmedia>

I need to cycle through the available image tags and print them into 5 column table. Here is my current xslt:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
	<xsl:output doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd"[/URL] />
	<xsl:param name="Key"/> 
   <xsl:template match="/" >
		<html>
			<head>
				<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
		        <xsl:element name="link">
		          <xsl:attribute name="rel">stylesheet</xsl:attribute>
		          <xsl:attribute name="href">../styles/main.css</xsl:attribute>
		        </xsl:element>				
				<title>Our Multimedia</title>
				<SCRIPT language="javascript" type="text/javascript">
				function leave()
				{
					box = document.forms[0].subbox;
					location.href= 'index.asp?Key=' + box.options[box.selectedIndex].value;
				}
				</SCRIPT>				
			</head>	
			<body>
			
				<div class="hdrcontainer">
					<div class="hdr_background">Raker's Layer</div>
					<div class="hdr_foreground">Raker's Layer</div>
					<div class="hdr_subtitle">...See and Hear It</div>
				</div>
			
				<div class="treebuttonscontainer ">
					<div class="treebuttons ">
						<a href="/articles">Articles</a>		
						<a href="/news">Past News</a>
						<span class="atPage">Media</span>				
						<a href="/myscripts">Scripts</a>
						<a href="/fockers">Fockers United</a>
						<a href="/">Home</a>
					</div>
				</div>	
				<div class="mainBody">
					<form name="bdy">
						<select name="subbox" onChange="javascript:leave();">
							<option value="">-- Select a Library --</option>
							<xsl:for-each select="webmedia/subject">
								<option>
									<xsl:attribute name="value">
										<xsl:value-of select="@name" />
									</xsl:attribute>
									<xsl:value-of select="@name" />
								</option>
							</xsl:for-each>
						</select>
						<br />					
						<xsl:for-each select="webmedia/subject[@name=$Key]">
							<table border="1">
								<tr>
									<td>
										<xsl:value-of select="@name" />
									</td>
								</tr>
								<xsl:for-each select="images/image">
									<tr>
										<td>
											<xsl:value-of select="@name" />
										</td>
									</tr>	
								</xsl:for-each>
							</table>
						</xsl:for-each>
					</form>
				</div>				
			</body>				
		</html>
   </xsl:template>
</xsl:stylesheet>

I am certain this will be simple, but I can't find any samples. Any suggestions?
 
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
   <xsl:template match="/">
     <table border="1">
       <tbody>
         <xsl:apply-templates select="webmedia/subject/images/image[position() mod 5=1]"/>
       </tbody>
     </table>
   </xsl:template>
   <xsl:template match="image[position() mod 5=1]">
     <tr>
       <td><image src="{concat(@href,@name)}" alt="{@id}"/></td>
       <xsl:apply-templates select="following-sibling::node()[position() &lt; 5]"/>
     </tr>
   </xsl:template>
   <xsl:template match="image[not(position() mod 5=1)]">
     <td><image src="{concat(@href,@name)}" alt="{@id}"/></td>
   </xsl:template>
</xsl:stylesheet>
If your image tags are not all together you'll have to put them in a nodeset first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top