Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

output html from XML - XSLT

Posted on 2006-05-31
4
Medium Priority
?
278 Views
Last Modified: 2013-11-19
Hi All
I have just got into XSLT basically i am doing a simple HTML transform.  I want to be able to use an image with a few more details than just src.....

my xml.
<area Title="Area1">
<image>image source</image>
</area>
my xslt.

<xsl:template match="area">
    <p class="HelpPages">
      <xsl:apply-templates/>
    </p>
  </xsl:template>

<xsl:template match="image">
    <img>
      <xsl:attribute name="src">
        <xsl:apply-templates/>
      </xsl:attribute>
    </img>
  </xsl:template>

I have other templates for different XML tags.
THIS WORKS.

What i want to do is
<image src="path" width="45" height="45"/>

So how do i access the src. width values?? i have tried....

<xsl:template match="image">
    <img>
      <xsl:attribute name="src">
        <xsl:value-of select="image/@src"/>
      </xsl:attribute>
    </img>
  </xsl:template>
 but with no joy....i have also tried select="@src" and select="area/image/@src".

looking at this link http://www.stylusstudio.com/xsllist/200008/post30330.html its seems pretty straight forward....what am i missing?

thanks
steve

0
Comment
Question by:osiris247
  • 2
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 16797008
<xsl:template match="image">
    <img>
      <xsl:attribute name="src">
        <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:attribute name="width">45</xsl:attribute>
      <xsl:attribute name="height">45</xsl:attribute>
    </img>
  </xsl:template>

The value you want to use as src is the text of the node rather than an attribute and, since Image is the context node in your template, you just use . (dot) to get its value.
0
 
LVL 7

Author Comment

by:osiris247
ID: 16797031
thank Carl

but what i want is to use the attribute so i can specify different widths etc. (good to know about the dot thing though)

I want my XML to look like this...
<image src="path" width="45" height="45"/>


Steve
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16797047
Oh, sorry, misunderstood.

If your XML looks like:   <image src="path" width="45" height="45"/>

Then the "image" template in your XSLT becomes:

    <xsl:template match="image">
        <img>
          <xsl:attribute name="src">
            <xsl:value-of select="."/>
          </xsl:attribute>
          <xsl:attribute name="width"><xsl:value-of select="@width" /></xsl:attribute>
          <xsl:attribute name="height"><xsl:value-of select="@height" /></xsl:attribute>
       </img>
     </xsl:template>
0
 
LVL 7

Author Comment

by:osiris247
ID: 16797153
Excellent thanks carl....

except i had to change
<xsl:attribute name="src">
            <xsl:value-of select="."/>
</xsl:attribute>
to..
<xsl:attribute name="src">
            <xsl:value-of select="@src"/>
</xsl:attribute>

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question