 |
| 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
|
|
|
|

August 6th, 2006, 06:27 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
|

August 7th, 2006, 11:04 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Try width='{@width}' height='{@height}'
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

August 7th, 2006, 12:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
|

August 8th, 2006, 04:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

August 8th, 2006, 06:00 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
|

August 8th, 2006, 07:35 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You need to post the actual XML.
--
Joe ( Microsoft MVP - XML)
|
|

August 8th, 2006, 08:12 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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!
|
|

August 9th, 2006, 03:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

August 9th, 2006, 12:09 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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>
|
|

August 9th, 2006, 03:51 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|
 |