Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2014, 04:53 PM
Authorized User
 
Join Date: Mar 2014
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default problem setting width and height of element by %

Hello,

I'm trying to set the width and height attribute on an img element to 50%. The following code doesn't work:

<xsl:element name="img">
<xsl:attribute name="src">...</xsl:attribute>
<xsl:attribute name="width">50%</xsl:attribute>
<xsl:attribute name="height">50%</xsl:attribute>
</xsl:element>

I tried CSS as well, but that didn't work either:

<xsl:element name="img">
<xsl:attribute name="src">...</xsl:attribute>
<xsl:attribute name="style">width: 50%; height: 50%;</xsl:attribute>
</xsl:element>

I don't want to use absolute values. I would really like to know how (if it's possible) to set the CSS of HTML elements using XSLT. Can this be done? If not, can I at least set the width and height of elements using percentages?

Thanks.
 
Old June 11th, 2014, 05:13 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What HTML are you trying to generate? If you can't work that out then you have an HTML problem, not an XSLT problem.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 12th, 2014, 10:14 AM
Authorized User
 
Join Date: Mar 2014
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

I'm trying to shrink the size of an image.

I'm expecting the HTML to look like this:

<img src="..." width="50%" height="50%">

or, if I can inject CSS:

<img src="..." style="width: 50%; height: 50%;">
 
Old June 12th, 2014, 11:22 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Either of the XSLT fragments above should generate the correct XSLT as far as I can tell.

Obviously we can't see your input XML, and you haven't shown us what the actual output it is generating is (i.e. what it is doing wrong).

You are aware that "50%" for the width of an image doesn't mean 50% of the width of the actual image, but 50% of whatever the width of the parent element is (if indeed it has a calculated width).

http://www.w3schools.com/CSSref/pr_dim_width.asp

Again, this sounds more like the HTML you are generating is not doing what you are expecting, rather than an issue generating the HTML, and as such it is not an XSLT issue.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 12th, 2014, 11:55 AM
Authorized User
 
Join Date: Mar 2014
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
Either of the XSLT fragments above should generate the correct XSLT as far as I can tell.

Obviously we can't see your input XML, and you haven't shown us what the actual output it is generating is (i.e. what it is doing wrong).

You are aware that "50%" for the width of an image doesn't mean 50% of the width of the actual image, but 50% of whatever the width of the parent element is (if indeed it has a calculated width).

http://www.w3schools.com/CSSref/pr_dim_width.asp

Again, this sounds more like the HTML you are generating is not doing what you are expecting, rather than an issue generating the HTML, and as such it is not an XSLT issue.
Ok, just wanted to confirm. Thanks for your help samjudson.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Get image height and width Dj Kat Javascript How-To 10 June 4th, 2009 01:49 PM
Chapter 2: width/height mcleod BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 5 May 24th, 2007 09:55 PM
how can I get width/height of a picture? keyvanjan Classic ASP Basics 2 May 29th, 2006 07:29 AM
Height and Width? venkatesh_anmca Beginning VB 6 0 January 31st, 2005 05:13 AM
Change height of div element if < window height JoelJunstrom Javascript How-To 1 October 10th, 2003 09:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.