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 March 16th, 2006, 03:26 PM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT and Google Mini

I'm new to XSL, but we recently got a Google Mini server here and I ran into som e coding issues when trying to customize the XSLT stylesheet. I have been able to find my way around and modify plenty of things but I am having trouble with some custom code...

What I am trying to do is check for a meta tag named gimag and if it exists, display a product image (the value of the meta tag is the image file path.) I have been able to do that fine, but when that meta tag doesn't exist I want to display a transparent image (so all the search results line up correctly.)

Here is what I have so far which isn't working:


<xsl:text disable-output-escaping="yes">&lt;td width="67" align="center"&gt;</xsl:text>
<xsl:if test="MT">
<xsl:for-each select="MT">
<xsl:if test="@N='gimage' and @V!=''">
<xsl:choose>
<xsl:when test="@N='gimage' and @V!=''">
<xsl:text disable-output-escaping="yes">&lt;a href=&quot;</xsl:text>
<xsl:value-of select="$full_url"/>
<xsl:text disable-output-escaping="yes">&quot;&gt;</xsl:text>
<img align="absmiddle" src="{@V}" height="60" border="0"/><xsl:text disable-output-escaping="yes">&lt;/a&gt;&lt;/td&gt;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping="yes">&lt;img align="left" src="http://www.atomicpark.com/images/accents/transparent-5x3.gif" width="62" height="60" /&gt;&lt;/td&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:if>

What am I doing wrong?

Thanks.

Al Dugan
www.atomicpark.com
__________________
Al Dugan
www.atomicpark.com
 
Old March 16th, 2006, 04:09 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

get rid of your outer
<xsl:if test="@N='gimage' and @V!=''">

you're already doing that test in your <xsl:when statement.
 
Old March 16th, 2006, 04:26 PM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get funky results when I do that... but I do think you are right, there's just something else wrong too... the transparent image does end up showing when I do that but it shows like 7 times???

I think it is because that <xsl:if test="MT"> finds all the meta tags not just gimage??? That's the only way I can figure why the transparent image would display multiple times.

Al Dugan
www.atomicpark.com
 
Old March 17th, 2006, 06:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This kind of XSLT code is horrible, it's an abuse of the language. disable-output-escaping is a hack which is intended for quite exceptional situations, like dealing with input that has been double-escaped. Using it as the routine way of creating elements and attributes is just a crazy way of coding.

I'm sorry, if you didn't write this code then this isn't a very helpful response, but my own approach to code like this is that I wouldn't touch it with a bargepole, and I'd recommend you do the same.

Do some googling around "disable-output-escaping considered harmful"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 17th, 2006, 10:35 AM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmmm... that's interesting. You would think a huge company like Google would do things correctly. (This section of code was put together by myself with sections from a forum post at Google. Also, even the default XSLT for the Google mini is full of disable-output-escaping.)

Al Dugan
www.atomicpark.com
 
Old March 17th, 2006, 10:38 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In my experience, the bigger the company, the more likely they are to do things wrong.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 17th, 2006, 10:49 AM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So is there a way to do this portion of the code right without having to rewrite the entire stylesheet? I can understand how you would be bothered by code "hacks" being the professional that you are... but in my case I just want this to work. I have no plans on becoming a seasoned XSL programmer. I'm an SEO and I'm just trying to make our internal search results look top notch.

See where I'm coming from?;)

Al Dugan
www.atomicpark.com
 
Old March 17th, 2006, 11:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, I see your problem. But I'm not interested in helping you with it. Sorry!

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Mini dump file Baby_programmer BOOK: Professional Team Foundation Server ISBN: 0-471-91930-6 0 June 25th, 2008 03:37 PM
Need Help in LoginStatus and Asp:ImageButton [Mini kamii47 ASP.NET 2.0 Basics 0 September 1st, 2007 04:24 PM
Google gragle prakon HTML Code Clinic 2 February 27th, 2007 01:51 PM
VB.Net tutorial / mini application Vaughn VB.NET 2002/2003 Basics 1 January 10th, 2005 05:40 PM





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