Results 1 to 2 of 2

Thread: XML image

  1. #1
    Join Date
    Dec 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default XML image

    Trying to get into xml. Lets say I have an XML document with an attached XSLT style sheet similar to this:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="search_results.xsl"?>
    <results>
    <profile id="01">
    <name>
    <first>Fred</first>
    <last>Noone</last>
    </name>
    <img src="fred.jpg" />
    </profile>
    <profile id="02">
    <name>
    <first>Cindy</first>
    <last>Someone</last>
    </name>
    <img src="cindy.jpg" />
    </profile>
    </results>

    with XSLT looking like this:

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="html"/>
    <xsl:template match="/">
    <style>
    div.profile{
    border:1px solid red;
    width:350px;
    height:200px;
    }
    div.name{
    border:1px dashed blue;
    width:100%;
    }
    span.name{
    font.weight:bold; font.style:arial;
    }
    </style>
    <html>
    <head>
    <title>Search Results</title>
    </head>
    <body>
    <xsl:apply-templates />
    </body>
    </html>
    </xsl:template>
    <xsl:template match="profile">
    <div class="profile">
    <xsl:apply-templates />
    </div>
    </xsl:template>
    <xsl:template match="name">
    <div class="name">
    <span class="name">
    <xsl:value-of select="last" />,
    <xsl:value-of select="first" />
    </span>
    </div>
    </xsl:template>
    I would like the image to get added here as simple html img
    </xsl:stylesheet>

    --my question is how to add the image into the style sheet to display...I have posted where I would like it to go inside the style sheet.

    Thanks in advance

  2. #2
    Join Date
    Dec 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default the answer

    The answer is easy. I guess it just looked complicated the way I posted it:

    in the xml:
    <img>
    <src>fred.jpg</src>
    </img>

    in the xslt put the desired output item in brackets:
    <xsl:for-each select="results/profile">

    <xsl:for-each select="img">
    <img class="profile" src="{src}" />
    </xsl:for-each>

    </xsl:for-each>

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
  •