467,226 Members | 1,425 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,226 developers. It's quick & easy.

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
  • viewed: 1808
Share:
6 Replies
jkmyoung
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
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
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

Post your reply

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

Similar topics

8 posts views Thread by jbrewer | last post: by
12 posts views Thread by Charlie King | last post: by
reply views Thread by CDMAPoster@FortuneJames.com | last post: by
5 posts views Thread by Ricardo Furtado | last post: by
13 posts views Thread by Ari Krupnik | last post: by
8 posts views Thread by Jon Slaughter | last post: by
2 posts views Thread by =?Utf-8?B?S2VuTg==?= | last post: by
5 posts views Thread by Roderik | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.