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 October 16th, 2010, 01:00 PM
Registered User
 
Join Date: Oct 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML and XSL styling issue

here is my xml file

Code:
<ProductResponse xmlns="http://www.mywebsearch.com/services/catalog">
<Products totalResults="2000" includedResults="10">
<Product id="1539555448" categoryId="499">
<title>Apple iPod touch 8GB (3rd Generation)</title>
<description>
Up to 1,750 songs  UP to 10 hours video  Audio Playback: Up to 30 hours  Video Playback: Up to 6 hours  Earphones, dock adapter, USB 2.0 cable  4.3 x 2.4 x 0.33 inches
</description>
<manufacturer>Apple</manufacturer>
<url>
http://www.mywebsearch.com/appleipodtouch8gb3rdgenerationpid1539555448/compareprices__rfaf1__af_assettype_id10__af_creative_id6__af_id37427__af_placement_id1.html
</url>
<Images>
<Image ysize="60" xsize="60">http://mysearch.com/resize?sq=60&uid=1539555448</Image>
<Image ysize="100" xsize="100">
http://mysearch.com/resize?sq=100&uid=1539555448
</Image>
<Image ysize="160" xsize="160">
http://mysearch.com/resize?sq=160&uid=1539555448
</Image>

<Image ysize="400" xsize="400">
http://mysearch.com/resize?sq=400&uid=1539555448
</Image>
</Images>
<Skus>
<sku>0885909313013</sku>
<sku>12510109</sku>
<sku>885909313013</sku>
<sku>MC086LL/A</sku>
<sku>MC086LLA</sku>
</Skus>
<relevancy>2412893567975424.000000</relevancy>
<Rating value="4.28">
<Image ysize="13" xsize="80">
http://mysearch.com/site/rating_4_and_half_star_80x13.gif
</Image>
</Rating>
<PriceSet>
<minPrice integral="14299">$142.99</minPrice>
<maxPrice integral="24165">$241.65</maxPrice>
<stores>17</stores>
</PriceSet>
</Product>
</Products>
</ProductResponse>
here is my xsl file

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:output method="html"/>
    <xsl:template match="/">
	<html>
            <body>
                <xsl:apply-templates select="ProductResponse/Products/Product"/>
            </body>
        </html>
    </xsl:template>
	
	    <xsl:template match="ProductResponse/Products/Product">
		<table>
			<tr>
 				<td><xsl:value-of select="title"/></td>
      			<td><xsl:value-of select="description"/></td>
			</tr>
		</table>
    </xsl:template>
    
</xsl:stylesheet>
</body>
</html>
result is not render properly can anyone please identify and correct my mistake.
thank you in advance
 
Old October 18th, 2010, 03:17 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

There's a few issues with what you've posted. The input document has "&" symbols in it. This will cause problems for parsers potentially. They should show up as escaped characters "&amp;", so I've corrected those.

The primary reason your transformation will not work properly is because your document is in the default "xmlns="http://www.mywebsearch.com/services/catalog" " namespace, but your transformation is trying to apply-templates on nodes that are in no namespace.

This can be corrected 2 ways. Since you're using XSLT 1.0, you can match nodes using the local-name() function to make it namespace agnostic. (eg. match="*[local-name() = 'Products'] ). Or in your transformation, you can assign the default namespace a dummy prefix and use that in your transformation. The later is what I corrected and did in your document. (If you were using XSLT 2.0, there are easier ways to do this.)

This obviously doesn't produce something that is along the lines of what you want, but you now know why it wasn't doing anything at all. You should be able to figure more out from here.

Document
Code:
<ProductResponse xmlns="http://www.mywebsearch.com/services/catalog">
    <Products totalResults="2000" includedResults="10">
        <Product id="1539555448" categoryId="499">
            <title>Apple iPod touch 8GB (3rd Generation)</title>
            <description>Up to 1,750 songs  UP to 10 hours video  Audio Playback: Up to 30 hours  Video Playback: Up to 6 hours  Earphones, dock adapter, USB 2.0 cable  4.3 x 2.4 x 0.33 inches</description>
            <manufacturer>Apple</manufacturer>
            <url>http://www.mywebsearch.com/appleipodtouch8gb3rdgenerationpid1539555448/compareprices__rfaf1__af_assettype_id10__af_creative_id6__af_id37427__af_placement_id1.html</url>
            <Images>
                <Image ysize="60" xsize="60">http://mysearch.com/resize?sq=60&amp;uid=1539555448</Image>
                <Image ysize="100" xsize="100">http://mysearch.com/resize?sq=100&amp;uid=1539555448</Image>
                <Image ysize="160" xsize="160">http://mysearch.com/resize?sq=160&amp;uid=1539555448</Image>
                <Image ysize="400" xsize="400">http://mysearch.com/resize?sq=400&amp;uid=1539555448</Image>
            </Images>
            <Skus>
                <sku>0885909313013</sku>
                <sku>12510109</sku>
                <sku>885909313013</sku>
                <sku>MC086LL/A</sku>
                <sku>MC086LLA</sku>
            </Skus>
            <relevancy>2412893567975424.000000</relevancy>
            <Rating value="4.28">
                <Image ysize="13" xsize="80">http://mysearch.com/site/rating_4_and_half_star_80x13.gif</Image>
            </Rating>
            <PriceSet>
                <minPrice integral="14299">$142.99</minPrice>
                <maxPrice integral="24165">$241.65</maxPrice>
                <stores>17</stores>
            </PriceSet>
        </Product>
    </Products>
</ProductResponse>
Transformation
Code:
<xsl:stylesheet version="1.0" xmlns:tns="http://www.mywebsearch.com/services/catalog" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
    <xsl:output method="html" />

    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates select="/tns:ProductResponse/tns:Products/tns:Product"/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="/tns:ProductResponse/tns:Products/tns:Product">
        <table>
            <tr>
                <td>
                    <xsl:value-of select="tns:title"/>
                </td>
                <td>
                    <xsl:value-of select="tns:description"/>
                </td>
            </tr>
        </table>
    </xsl:template>
</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSl - FO issue. anarleti XSLT 2 August 16th, 2010 02:08 PM
XSL for-each issue test7 XSLT 7 July 27th, 2010 04:33 PM
xsl:copy-of Issue DKatSSA BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 8 November 19th, 2008 05:18 PM
XSL Issue mickhughes XSLT 4 October 18th, 2007 08:29 AM
xsl:sort and IE 5.0 Issue babloo81 XSLT 1 March 17th, 2004 06:12 AM





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