473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

if no image in xml use this image instead.

Hello,

I haven't made a XSL in quite sometime so i am very rusty. Basicly i want the XSL to display a defined image if one is not present in the XML.

here is my current XSL and XML will be below that, hope you can help.

Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0' encoding='utf-8' ?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">
  3. <xsl:output method="html" encoding="ISO-8859-1" omit-xml-declaration="yes"/>
  4.  
  5.     <xsl:param name="pagename">default.asp?pagename=media&amp;content=getcontent</xsl:param>
  6.     <xsl:param name="lang">en</xsl:param>
  7.     <xsl:param name="type">print</xsl:param>
  8.     <xsl:param name="vol">200304</xsl:param>
  9.     <xsl:param name="cat">2</xsl:param>
  10.     <xsl:param name="articleid">12345</xsl:param>
  11.     <xsl:param name="mode">preview</xsl:param>
  12.     <xsl:param name="target">email</xsl:param>
  13.  
  14.     <xsl:variable name="strBaseURL"><xsl:value-of select="concat('type=',$type,'&amp;lang=',$lang,'&amp;vol=',$vol,'&amp;cat=',$cat,'&amp;articleid=',$articleid)"></xsl:value-of></xsl:variable>
  15.  
  16.     <xsl:variable name="default" select="document('../xml/default.xml')/main/site[@language=$lang]"/>
  17.  
  18.     <xsl:variable name="website_IP"><xsl:value-of select="$default/website_IP"/></xsl:variable>
  19.  
  20.     <xsl:variable name="twidth">
  21.         <xsl:choose>
  22.             <xsl:when test="$target='web'"><xsl:text>100%</xsl:text></xsl:when>
  23.         <xsl:otherwise><xsl:text>750</xsl:text></xsl:otherwise>
  24.         </xsl:choose> 
  25.     </xsl:variable>
  26.  
  27.     <xsl:variable name="image_dir">
  28.         <xsl:choose>
  29.             <xsl:when test="$target='web'"><xsl:value-of select="$default/web_article_images_url"/></xsl:when>
  30.             <xsl:when test="$target='email' or $target='index'"><xsl:value-of select="$website_IP"/><xsl:value-of 
  31.  
  32. select="$default/web_article_images_url"/></xsl:when>
  33.             <xsl:when test="$target='cd'"><xsl:value-of select="$default/cd_article_images_url"/></xsl:when>
  34.         </xsl:choose>
  35.             </xsl:variable>
  36.  
  37.  
  38.  
  39. <xsl:variable name="viewpagename"><xsl:text>default.asp?pagename=media&amp;content=getcontent</xsl:text></xsl:variable>
  40. <xsl:variable name="downloadpagename"><xsl:text>default.asp?pagename=media&amp;content=getcontent</xsl:text></xsl:variable>
  41.  
  42. <xsl:template match="vol_issue">
  43.     <xsl:variable name="view_text">
  44.         <xsl:choose>
  45.             <xsl:when test="type = 'print' or type = 'web'">
  46.                 <xsl:choose>
  47.                     <xsl:when test="language='en'">View this article</xsl:when>
  48.                     <xsl:otherwise>Visualiser cet article</xsl:otherwise>
  49.                 </xsl:choose>
  50.             </xsl:when>
  51.             <xsl:when test="type = 'digital'">
  52.                 <xsl:choose>
  53.                     <xsl:when test="language='en'">Watch this video</xsl:when>
  54.                     <xsl:otherwise>Regarder ce vidéo</xsl:otherwise>
  55.                 </xsl:choose>
  56.             </xsl:when>
  57.             <xsl:when test="type = 'pr'">
  58.                 <xsl:choose>
  59.                     <xsl:when test="language='en'">View this release</xsl:when>
  60.                     <xsl:otherwise>Visualiser ce communiqué</xsl:otherwise>
  61.                 </xsl:choose>
  62.             </xsl:when>
  63.             <xsl:otherwise>
  64.                 <xsl:choose>
  65.                     <xsl:when test="language='en'">View this script</xsl:when>
  66.                     <xsl:otherwise>Visualiser ce script</xsl:otherwise>
  67.                 </xsl:choose>
  68.             </xsl:otherwise>
  69.         </xsl:choose>
  70.     </xsl:variable>
  71.  
  72.     <xsl:variable name="email_text">
  73.         <xsl:choose>
  74.             <xsl:when test="type ='print' or type='web'">
  75.                 <xsl:choose>
  76.                     <xsl:when test="language='en'">E-mail me this article</xsl:when>
  77.                     <xsl:otherwise>Veuillez me transmettre cet article par courriel</xsl:otherwise>
  78.                 </xsl:choose>
  79.             </xsl:when>
  80.             <xsl:when test="type ='pr'">
  81.                 <xsl:choose>
  82.                     <xsl:when test="language='en'">E-mail me this release</xsl:when>
  83.                     <xsl:otherwise>Envoyer ce communiqué par courriel</xsl:otherwise>
  84.                 </xsl:choose>
  85.             </xsl:when>
  86.             <xsl:when test="type ='digital'">
  87.             </xsl:when>
  88.             <xsl:otherwise>
  89.                 <xsl:choose>
  90.                     <xsl:when test="language='en'">E-mail me this script</xsl:when>
  91.                     <xsl:otherwise>Veuillez me transmettre ce script par courriel</xsl:otherwise>
  92.                 </xsl:choose>
  93.             </xsl:otherwise>
  94.             </xsl:choose>
  95.             </xsl:variable>        
  96.     <xsl:variable name="cat_description" select="document('../articles/categories.xml')/main/category[@category_id = $cat]/description"/>
  97.     <div class="m-bcategory"><h1><xsl:value-of select="$cat_description"/></h1></div>
  98.     <xsl:for-each select="category[@category_id = $cat]/article">
  99.       <xsl:variable name="article" select="document(concat('../articles/', @article_id, '.xml'))"/>
  100.         <div class="m-blurbwrapper">
  101.         <div class="m-bheadline"><a class="m-bheadline" 
  102.  
  103. href="{$viewpagename}&amp;type={../../type}&amp;lang={../../language}&amp;vol={../../@vol_issue_id}&amp;cat={../@category_id}&amp;articleID={@article_id}&amp;mode=view&amp;id={$article/article/video/file/file_name}"><xsl:value-of select="$article/article/headline"/></a></div>
  104.  
  105.  
  106.     <div style="float:left;"><img src="{$image_dir}{$article/article/images/image/source}" border="0" width="70" height="50"/>
  107.             </div>
  108.  
  109.  
  110.          <div class="m-awordcount"><xsl:value-of select="$article/article/body_text/wordcount"/></div>
  111.  
  112.            <div class="m-bblurb"><xsl:value-of select="$article/article/blurb"/></div>
  113.  
  114.  
  115.         <div class="m-blink">
  116.           <a class="m-blink" 
  117.  
  118. href="{$viewpagename}&amp;type={../../type}&amp;lang={../../language}&amp;vol={../../@vol_issue_id}&amp;cat={../@category_id}&amp;articleID={@article_id}&amp;mode=view&amp;id={$article/article/video/file/file_name}">
  119.             <xsl:value-of select="$view_text"/>
  120.           </a>
  121.           <xsl:if test="../../type='print' or ../../type='web' or ../../type='pr' or ../../type='digital'">
  122.             ***<a  class="m-blink" 
  123.  
  124. href="{$downloadpagename}&amp;type={../../type}&amp;lang={../../language}&amp;vol={../../@vol_issue_id}&amp;cat={../@category_id}&amp;articleID={@article_id}&amp;mode=email">
  125.               <xsl:value-of select="$email_text"/>
  126.             </a>
  127.           </xsl:if>
  128.         </div>
  129.      </div>
  130.     </xsl:for-each>
  131. </xsl:template>
  132. </xsl:stylesheet>
XML

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE article SYSTEM "article.dtd" [
  3. ]>
  4. <article>
  5. <headline>display this works</headline>
  6. <subheadline></subheadline>
  7. <blurb>display this works</blurb>
  8. <byline></byline>
  9. <copyright></copyright>
  10. <body_text></body_text>
  11. <images>
  12. <image>
  13. <source>someimage.jpg</source>
  14. <res_type>low</res_type>
  15. </image>
  16. <image>
  17. <source>someimage.jpg</source>
  18. <res_type>hi</res_type>
  19. </image>
  20. </images>
  21. <audio>
  22. <file>
  23. <file_name></file_name>
  24. <file_type></file_type>
  25. </file>
  26. </audio>
  27. <video></video>
  28. </article>
Sep 13 '07 #1
6 2210
jkmyoung
2,057 Expert 2GB
Where you have:
<img src="{$image_dir}{$article/article/images/image/source}" />

replace with something like:

<img border="0" width="70" height="50">
<xsl:attribute name="src">
<xsl:value-of select="$image_dir"/>
<xsl:value-of select="$article/article/images/image/source"/>
<xsl:if test="not($article/article/images/image/source)">defaultimage.jpg</xsl:if>
</xsl:attribute>
</img>
Sep 13 '07 #2
Well i tried your solution, and i just get the same efftect.

If the image is in the XML it displays the image but if no image in the XML
I just get an image cell (i am starting to hate that red x)
Sep 14 '07 #3
jkmyoung
2,057 Expert 2GB
The above assumes that you have the defined image in defaultimage.jpg
Perhaps your defined image is named differently?

It also assumed your defined image was in the same image directory.
Sep 14 '07 #4
The above assumes that you have the defined image in defaultimage.jpg
Perhaps your defined image is named differently?

It also assumed your defined image was in the same image directory.
Expand|Select|Wrap|Line Numbers
  1. <div style="float:left;">
  2.             <img border="0" width="70" height="50">
  3.             <xsl:attribute name="src">
  4.             <xsl:value-of select="$image_dir"/>
  5.             <xsl:value-of select="$article/article/images/image/source"/>
  6.             <xsl:if test="not($article/article/images/image/source)">noimage.jpg</xsl:if>
  7.             </xsl:attribute>
  8.             </img>
  9.             </div>
yes the image is in the dir, though it still does not display.
Sep 14 '07 #5
jkmyoung
2,057 Expert 2GB
ah, do you have an empty existing source node?
Instead change the if test to:
<xsl:if test="$article/article/images/image/source = ''">noimage.jpg</xsl:if>

which instead tests if the the string is empty as opposed to the node not being there.
Sep 14 '07 #6
ah, do you have an empty existing source node?
Instead change the if test to:
<xsl:if test="$article/article/images/image/source = ''">noimage.jpg</xsl:if>

which instead tests if the the string is empty as opposed to the node not being there.

Ah i knew it was something small that i was over looking, thank you for your input and help, that works perfectly.

Thank you again.
Sep 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: jbrewer | last post by:
I'm trying to read in a FITs image file for my research, and I decided that writing a file decoder for the Python imaging library would be the easiest way to accomplish this for my needs. FITs is...
12
by: Charlie King | last post by:
As I understand it, the use of FIR* to replace heading tags with images in visually enabled CSS browsers is now frowned upon on the basis that some screen readers will *nor* read back text that is...
24
by: Manuel | last post by:
Is it possible to embed an image, like a company logo in a CDOSYS generated message? If yes, I´ll apreciate some code sample. I´ve been able to format messages in html the way I like, but I...
0
by: CDMAPoster | last post by:
In: http://groups.google.com/group/comp.databases.ms-access/msg/9c3dcf952fc3e3d3 I said: '----- In: http://groups.google.com/group/comp.databases.ms-access/msg/c368352c1...
5
by: Ricardo Furtado | last post by:
I'm trying, for a week or two, to create a procedure in order to rotate the image in any picturebox control in a cephalometry software. I've found a web site that shows how that can be done:...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
13
by: Ari Krupnik | last post by:
Image.width returns the width of an image as it is displayed on a browser page, which may be different from the image's intrinsic size if the 'img' element had a 'width' attribute specified. Is...
8
by: Jon Slaughter | last post by:
can one "stream" image data to a browser? I created an image using gd and when I do imagepng I just get the binary data for the image written as text instead of the image itself. Now I'm...
2
by: =?Utf-8?B?S2VuTg==?= | last post by:
We're using a System.Windows.Forms.ImageList to store a bunch of Images that I've loaded, and rendering each image in the ImageList during a draw loop. The process was running unusually slow and...
5
by: Roderik | last post by:
Hi, I guess I am missing something. I tried to put a caption on my photo (on the bottom) but the caption appears to be a bit higher and overshooting the area of the image with a few pix. You...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.