Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2012, 12:30 AM
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL sitemap, trouble pulling values

Hello everyone, hope this is the right place. I am working on modifying a xsl sitemap template from http://yoast.com/xsl-stylesheet-xml-sitemap/

I've cleaned it up, as I'd like to use it as a image sitemap only, pulling the image url location, and caption from the xml. However, I have absolutely no idea how to modify the code to do this. I've played with a lot of changes however my programming knowledge is aweful.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
                xmlns:html="http://www.w3.org/TR/REC-html40"
				xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
                xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>XML Sitemap</title>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
				<script type="text/javascript" src="http://tablesorter.com/jquery.tablesorter.min.js"></script>
				<script	type="text/javascript"><![CDATA[
					$(document).ready(function() { 
				        $("#sitemap").tablesorter( { widgets: ['zebra'] } ); 
					});
				]]></script>
			</head>
			<body>
				<div id="content">
					<h1>XML Image Sitemap</h1>
					<p class="expl">
						This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.
					</p>			
					<table id="sitemap" cellpadding="3">
						<thead>
							<tr>
								<th width="75%">URL</th>
                                <th width="25%">Description</th>
							</tr>
						</thead>
						<tbody>
							<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
							<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
							<xsl:for-each select="sitemap:urlset/sitemap:url">
								<tr>
								  <td>
										<xsl:variable name="itemURL">
											<xsl:value-of select="sitemap:loc"/>
										</xsl:variable>
										<a href="{$itemURL}">
											<xsl:value-of select="sitemap:loc"/>
										</a>
									</td>
								</tr>
							</xsl:for-each>
						</tbody>
					</table>
				</div>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
My xml format is like this:
Code:
 <url>
       <loc>http://www.bookboxshop.com/product/davinci-project-bk-61/</loc>
         <image:image>
         <image:loc>http://www.bookboxshop.com/images/Leonardo-da-Vinci-Book-Box-Detail.png</image:loc>
         <image:caption>Leonardo da Vinci Book-Box</image:caption>
       </image:image>
  </url>

Currently, the xsl code pulls the <loc>, whereas I'd like it to display the <image:loc>. I'd like the description field to pull the <image:caption> field. I thought it would be simple, but it is beyond my efforts.

Any help would be tremendously appreciated!
Thanks
Michael

Last edited by mkowalski; June 21st, 2012 at 01:59 AM..
 
Old June 21st, 2012, 01:58 AM
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Figured it out! Thanks : )
 
Old June 22nd, 2012, 06:12 PM
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well I have a bit of a problem. I noticed that it does work correctly pulling the image url and the "caption"/description, but the problem is that in order for values to show, it needs to be contained within a <url></url>. However, since I have 30 images on a single page, it is not good to have the <url></url> for every image, since the url is the same for all the images.

If I modify the xml to list like this:
Code:
 <url>
       <loc>http://www.bookboxshop.com/products/</loc>
       <lastmod>2012-06-15T20:19:16+00:00</lastmod>
       <changefreq>weekly</changefreq>
       <priority>0.6400</priority>
       <image:image>
         <image:loc>http://www.bookboxshop.com/images/Chat-Noir-BK-58-209x180.png</image:loc>
         <image:caption>Chat Noir Book-Box Thumbnail</image:caption>
       </image:image>
       <image:image>
         <image:loc>http://www.bookboxshop.com/images/BK-63-209x180.png</image:loc>
         <image:caption>Picasso Book-Box Thumbnail</image:caption>
       </image:image>
</url>
</urlset>
It only pulls the first value and the rest are blank. I think it had to do with this section of code:
Code:
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
							<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
							<xsl:for-each select="sitemap:urlset/sitemap:url">
I've been playing with it for a bit now, as is it only lists the first. Any changes I've done so far have made the entries blank. I will keep trying, any suggestions greatly appreciated!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
values comparison in xsl sani723 XSLT 2 April 3rd, 2007 04:05 AM
Trouble Transforming an XML SOAP Response with XSL wsessoms XSLT 1 December 20th, 2006 01:47 PM
New User having trouble with Zero Values AngelaR Pro VB 6 1 January 8th, 2006 09:15 PM
Trouble with returning parameter values EricJ VB.NET 0 July 5th, 2005 08:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.