SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying images with XSL?

    I'm currently struggling to display an image with XML/XSL.

    Any pointers as to what I'm doing wrong.

    XSL
    Code:
    	<DIV ID="divMenuBar">
    	<TABLE ID="tblMenuBar" BORDER="0">
    	<TR>
    	<xsl:for-each select="//TOPICS[TOPIC]">
    		<TD CLASS="clsMenuBarItem">
    			<xsl:attribute name="ID">tdMenuBarItem<xsl:value-of select="@TYPE" /></xsl:attribute>
    		
    			<xsl:for-each select="PICTURE">
    			 <img src="{/SRC}"/>
    			</xsl:for-each>
    
    		
    		</TD>
    		<xsl:if test="context()[not(end())]">
    		</xsl:if>
    	</xsl:for-each>
    	</TR>
    	</TABLE>
    	</DIV>
    XML
    Code:
    <?xml version="1.0"?>
    <?xml:stylesheet type="text/xsl" href="menus.xsl"?>
    
    <TOPICLIST TYPE="NAVIGATION">
    
    <TOPICS TYPE="HOME">
    	<PICTURE>
    		<SRC>img/spacer1.gif</SRC>
    	</PICTURE>
    	<URL>http://www.rapidflame.com/index.asp</URL>
    	<TOPIC><TITLE>1</TITLE><URL>/workshop/author/dhtml/reference/objects.asp</URL></TOPIC>
    </TOPICS>
    </TOPICLIST>

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe you want to do something like this:

    Code:
    <xsl:for-each select="PICTURE">
      <xsl:element name="img">
         <xsl:attribute name="src"><xsl:value-of select="child::SRC"/></xsl:attribute>
      </xsl:element>
    </xsl:for-each>
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erm

    If I run that server side through ASP - I get the following error:

    Error Type:
    msxml3.dll (0x80004005)
    Expected token 'eof' found ':'. child-->--:SRC
    /includes/xml/xmltest/transform.asp, line 17

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've managed to fix it. Thanks for your input though.

    Correct code:

    <xsl:element name="img">
    <xsl:attribute name="src"><xsl:value-of select="SRC"/></xsl:attribute>
    </xsl:element>

  5. #5
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just one comment, if you're going to the trouble of using XML and XSLT, then you should at least have a stab at making your output XHTML compliant, which means lowercase tags and attributes e.g. <td> not <TD>
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •