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 August 6th, 2006, 06:27 PM
Friend of Wrox
 
Join Date: Jul 2006
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
 
Old August 7th, 2006, 11:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old August 7th, 2006, 12:13 PM
Friend of Wrox
 
Join Date: Jul 2006
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


 
Old August 8th, 2006, 04:32 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old August 8th, 2006, 06:00 AM
Friend of Wrox
 
Join Date: Jul 2006
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

 
Old August 8th, 2006, 07:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to post the actual XML.

--

Joe (Microsoft MVP - XML)
 
Old August 8th, 2006, 08:12 AM
Friend of Wrox
 
Join Date: Jul 2006
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!

 
Old August 9th, 2006, 03:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old August 9th, 2006, 12:09 PM
Friend of Wrox
 
Join Date: Jul 2006
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>
 
Old August 9th, 2006, 03:51 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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





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





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