Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 6th, 2006, 06:27 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default set image size from attribute

Hi All,

I am trying to set the size of an image for output in XSLT based on the attribute @height and @width. I want whom every is authoring the XML file to input the sizes. I am not sure how to do it.

Code:
Element
JBU:graphic
@href
@height
@width
Code:
    <xsl:template match="JBU:graphic">
        <xsl:if test="not(preceding-sibling::JBU:graphic)">
            <xsl:for-each select="..">
                <center>
                    <xsl:for-each select="JBU:graphic">
                        <xsl:for-each select="@href">
                            <img border="0" width='@width' height='@height'>
                                <xsl:attribute name="src"><xsl:if test="substring(string(.), 2, 1) = ':'"><xsl:text>file:///</xsl:text></xsl:if><xsl:value-of select="translate(string(.), '#x5c;', '/')"/></xsl:attribute>
                            </img>
                        </xsl:for-each>
                    </xsl:for-each>
                </center>
            </xsl:for-each>
        </xsl:if>
    </xsl:template>


Thanks for the help,

Bones
Reply With Quote
  #2 (permalink)  
Old August 7th, 2006, 11:04 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try width='{@width}' height='{@height}'

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 7th, 2006, 12:13 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thank you Michael, but it returns the following line in HTML:

Code:
<center><img border="0" width="" height="" src="Chart1.gif"></center>
I'll keep working at it.

Bones


Reply With Quote
  #4 (permalink)  
Old August 8th, 2006, 04:32 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In that case you' need to show the source document. Your template seems quite odd. You match JBU:graphic. You then for-each against its parent and then for-each against the JBU:graphic.


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old August 8th, 2006, 06:00 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi Joe,

Thank you for the reply. I am learning XSLT, which can explain why my template is odd.
Any suggestions?

How do I reference the source document?

Regards,

Bones

Reply With Quote
  #6 (permalink)  
Old August 8th, 2006, 07:35 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to post the actual XML.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #7 (permalink)  
Old August 8th, 2006, 08:12 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi Joe,

Here is the XML Reference:

Code:
<graphic href="Chart1.gif" width="100" height"100"/>
The href, height and width are attributes of <graphic>. I want the author to be able to set the image size.

Thanks!

Reply With Quote
  #8 (permalink)  
Old August 9th, 2006, 03:01 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show the whole XML?
With what you've given, assuming a default namespace is declared somewhere, Michael's suggestion should work.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #9 (permalink)  
Old August 9th, 2006, 12:09 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi Joe,

here is the XML file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Book xmlns="www.jb.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="www.jb.com
C:\DOCUME~1\MYDOCU~1\Sharing\old\JBLUMOMgraphic.xsd">
    <Chapter>
        <Title>Chapter 1</Title>
        <Sec1>
            <Para>
                <graphic width="40" height="40" href="Chart.gif"/>
            </Para>
        </Sec1>
    </Chapter>
    <booktitle/>
</Book>
Reply With Quote
  #10 (permalink)  
Old August 9th, 2006, 03:51 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Writing <xsl:for-each select="@href"> changes the context node to be the href attribute, the href attribute does not have a width or height attribute so they aren't picked up.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
set image on <asp:Image> stored in DataBase myself.panku ASP.NET 2.0 Professional 1 August 11th, 2008 10:41 AM
how set Attribute of Folder at Run Time Rahul Gupta Pro VB 6 2 October 17th, 2007 11:55 PM
set up image size goldenstate BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 February 15th, 2007 07:37 PM
Error - Attribute cannot be set now ajish_jose Access 6 February 1st, 2005 04:38 AM
Dynamically set selected attribute fs22 Javascript How-To 5 December 24th, 2004 04:10 PM



All times are GMT -4. The time now is 06:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.