• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

adding a picture in XSL

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a XML with NO images links.
I want to transform XML to HTML using XSLT, and add a picture on top, how do i do that?


I want to add something like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<head>
<style>
img {
width:100%;
}
</style>
</head>


<body>
<h2>My CD Collection</h2>

<img src="picture.jpg" alt="nice picture" style="width:128px;height:100px;">



<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


but no luck :-(
 
Marshal
Posts: 24927
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to questions like this is always:

1. Decide what HTML you want to produce.

2. Write XSLT which produces that HTML.

For step 1 you might want to produce that HTML in a text editor first, and make sure it does what you want.
 
Niklas Karlsson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is that "it works" as long as I don't put in a picture in the xls... :-(


so if i make only a "hard code HTML-file" :




but if i try to use this as a xls, I receive error.. :-(
 
Paul Clapham
Marshal
Posts: 24927
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you receive an error message then you should read it and deal with it. If you can't do that then by all means ask about it here, posting the relevant information.
 
Ranch Hand
Posts: 729
7
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I refer to post#1. xsl document must be xml-wellformed too. Line #15:

 
Niklas Karlsson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO :-(
it look strange when I try this..
please loot at an exampel:
a XML:


a XLS:


when I run this, it generate a strange HTML-code :-(


so it generate this:
<img src="picture.jpg">
and NOT this:
<img src="picture.jpg"/>
:-(
 
g tsuji
Ranch Hand
Posts: 729
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

NO :-(
it look strange when I try this..


No? Why do you think it is strange. It is a perfectly acceptable html rendering of img. The only thing you need to do is to make sure the xslt itself is well-formed. If you want a well-formed output (html) you put the method="xml" instead and have some minor detail to take care of if you need meta to be generated for you etc. Even if you do nothing about, browser as a user-agent won't complain much and would go ahead rendering it as html.
 
Niklas Karlsson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

g tsuji wrote:

NO :-(
it look strange when I try this..


No? Why do you think it is strange. It is a perfectly acceptable html rendering of img. The only thing you need to do is to make sure the xslt itself is well-formed. If you want a well-formed output (html) you put the method="xml" instead and have some minor detail to take care of if you need meta to be generated for you etc. Even if you do nothing about, browser as a user-agent won't complain much and would go ahead rendering it as html.



I use this HTML to convert it to pdf, and this must have "well formated" tags :-(
(for example on img-tags: it must have end tags..)
 
g tsuji
Ranch Hand
Posts: 729
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I use this HTML to convert it to pdf, and this must have "well formated" tags :-(
(for example on img-tags: it must have end tags..)


If you use whatever library/framework/utility-software which advertises that it can convert html to pdf, it better delivers without complaining the output not a bit.

[1] Now, if it won't deliver their promise, you can still at the xslt-output end of the chain of processes insert a step using with some api/utility usually called "html repair" or "beautifier" before passing to the broken html-pdf converter.

[2] You can do better by doing the necessary at the earlier stage of the chain of processes that I have already answered, namely. I quote myself, If you want a well-formed output (html) you put the method="xml", unquote. If you do not catch the gist of it, you do the following in the xslt.

I think this is the most readily understandable step you can take to end up with a conversion to pdf.

[3] Better still, you can do the following chain of processes, using xsl-fo (format-object) and use say Apache's fop to convert to pdf. Just to mention in passing, as I don't see you are ready for it yet.

[3.1] You can also not using Apache fop or some commercial equivalence, but instead use some other dedicated framework/library such as iText or something else to spare you from producing some useless intermediate objects such as html and directly convert the xml source to pdf adding the image on the way of doing it.
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!