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 October 10th, 2014, 11:35 PM
Registered User
 
Join Date: Oct 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Adding image through XSLT and images folder

I need to add a portrait of each president from the 21st century only. The images are saved in an images folder on the same level as the .xsl file. I need to add the images through the XSL file and cannot add anything to the XML file. I also can not use a for-each, it must keep the basic structure of my XSL file.

Here is what I was trying to do:
If the "president/number = 44" then show image "44.png" located in an images folder in the same folder as the .xsl file

Can you please help?

XSL file:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
				xmlns:fn="http://www.w3.org/2005/xpath-functions" >
				
	<xsl:output method="xhtml" 
				indent="yes"
				omit-xml-declaration="yes" />
				
	<xsl:template match="/">
		<html>
		<head>
		<title>Table of US Presidents</title>
		<link rel="stylesheet" type="text/css" href="president_21c.css" />
		</head>
		<body>
		<h1>Table of US Presidents</h1>
		
		<xsl:apply-templates select="presidents" />
	
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="presidents">
		<table>
		<tr>
		<th>Name</th>
		<th>Birthday</th>
		<th>Took Office</th>
		<th>Left Office</th>
		<th>Party</th>
		<th>Portrait</th>
		</tr>
			<xsl:apply-templates select="president" />
		</table>
	</xsl:template>
	
	<xsl:template match="president">
		<tr>
			<xsl:apply-templates select="name" />
			<xsl:apply-templates select="birthday" />
			<xsl:apply-templates select="took_office" />
			<xsl:apply-templates select="left_office" />
			<xsl:apply-templates select="party" />
			<xsl:apply-templates select="portrait" />
		</tr>
	</xsl:template>
	
	<xsl:template match="name">
		<td class="nameStyle">
			<xsl:value-of select="." />
		</td>
	</xsl:template>
	
	<xsl:template match="birthday">
		<td class="birthdayStyle">
			<xsl:value-of select="." />
		</td>
	</xsl:template>
	
	<xsl:template match="took_office">
		<td class="took_officeStyle">
				<xsl:value-of select="." />
		</td>
	</xsl:template>
	
	<xsl:template match="left_office">
		<td class="left_officeStyle">
				<xsl:value-of select="." />
		</td>
	</xsl:template>
	
	<xsl:template match="party">
			<xsl:choose>
				<xsl:when test=".='Federalist'">
				<td class="federalistParty">
				<xsl:value-of select="." />
				</td>
				</xsl:when>
				
				<xsl:when test=".='Democratic-Republican'">
				<td class="democrateRepublicanParty">
				<xsl:value-of select="." />
				</td>
				</xsl:when>
				
				<xsl:when test=".='Democratic'">
				<td class="democraticParty">
				<xsl:value-of select="." />
				</td>
				</xsl:when>
				
				<xsl:when test=".='Whig'">
				<td class="whigParty">
				<xsl:value-of select="." />
				</td>
				</xsl:when>
				
				<xsl:when test=".='Republican'">
				<td class="republicanParty">
				<xsl:value-of select="." />
				</td>
				</xsl:when>
				
				<xsl:otherwise>
				<td>
				<xsl:value-of select="." />
				</td>
				</xsl:otherwise>
			</xsl:choose>
		
	</xsl:template>
	
	<xsl:template match="portrait">
		<td class="portrait">
			<xsl:if test="'../president/number' = 44">
				<img src="{/images/44.png}" alt="Barack Obama Portrait" class="portraitStyle"/>
			</xsl:if>
		</td>
	</xsl:template>
	
	
</xsl:stylesheet>
XML file:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!-- Information about US Presidents -->
<?xml-stylesheet type="text/xsl" href="president_21c.xsl" ?>

<presidents date="2012-08-18" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="president.xsd">
			
    <president>
        <number>1</number>
        <name>George Washington</name>
        <birthday>1732-02-22</birthday>
        <took_office>1789-04-30</took_office>
        <left_office>1797-03-04</left_office>
        <party>no party</party>
        <term>
            <number>1</number>
            <vice_president>John Adams</vice_president> 
        </term>
        <term>
            <number>2</number>
            <vice_president>John Adams</vice_president>
        </term>
    </president>
    
    <president>
        <number>2</number>
        <name>John Adams</name>
    	<birthday>1735-10-30</birthday>
        <took_office>1797-03-04</took_office>
        <left_office>1801-03-04</left_office>
        <party>Federalist</party>
        <term>
            <number>3</number>
            <vice_president>Thomas Jefferson</vice_president>
        </term>
    </president>
    
    <president>
        <number>3</number>
        <name>Thomas Jefferson</name>
        <birthday>1743-04-13</birthday>
        <took_office>1801-03-04</took_office>
        <left_office>1809-03-04</left_office>
        <party>Democratic-Republican</party>
        <term>
            <number>4</number>
            <vice_president>Aaron Burr</vice_president>
        </term>
        <term>
            <number>5</number>
            <vice_president>George Clinton</vice_president>
        </term>
    </president>
    
    <president>
        <number>4</number>
        <name>James Madison</name>
        <birthday>1751-03-16</birthday>
        <took_office>1809-03-04</took_office>
        <left_office>1817-03-04</left_office>
        <party>Democratic-Republican</party>
        <term>
            <number>6</number>
            <vice_president>George Clinton</vice_president>
        </term>
        <term>
            <number>7</number>
            <vice_president>Elbridge Gerry</vice_president>
        </term>
    </president>

    <president>
        <number>5</number>
        <name>James Monroe</name>
        <birthday>1758-04-28</birthday>
        <took_office>1817-03-04</took_office>
        <left_office>1825-03-04</left_office>
        <party>Democratic-Republican</party>
        <term>
            <number>8</number>
            <vice_president>Daniel D. Tompkins</vice_president>
        </term>
        <term>
            <number>9</number>
            <vice_president>Daniel D. Tompkins</vice_president>
        </term>
    </president>
    
    <president>
        <number>6</number>
        <name>John Quincy Adams</name>
        <birthday>1767-07-11</birthday>
        <took_office>1825-03-04</took_office>
        <left_office>1829-03-04</left_office>
        <party>Democratic-Republican</party>
        <term>
            <number>10</number>
            <vice_president>John C. Calhoun</vice_president>
        </term>
    </president>
    
    <president>
        <number>7</number>
        <name>Andrew Jackson</name>
        <birthday>1767-03-15</birthday>
        <took_office>1829-03-04</took_office>
        <left_office>1837-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>11</number>
            <vice_president>John C. Calhoun</vice_president>
        </term>
        <term>
            <number>12</number>
        <vice_president>Martin Van Buren</vice_president>
        </term>
    </president>
    
    <president>
        <number>8</number>
        <name>Martin Van Buren</name>
        <birthday>1782-12-05</birthday>
        <took_office>1837-03-04</took_office>
        <left_office>1841-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>13</number>
            <vice_president>Richard Mentor Johnson</vice_president>
        </term>
    </president>
    
    <president>
        <number>9</number>
        <name>William Henry Harrison</name>
        <birthday>1773-02-09</birthday>
        <took_office>1841-03-04</took_office>
        <left_office>1841-04-04</left_office>
        <!-- Looked up Presidents political party and added info to XML to match DTD requirements. Information from: http://www.history.com/topics/us-presidents/william-henry-harrison -->
        <party>Whig</party>
        <term>
            <number>14</number>
            <vice_president>John Tyler</vice_president>
        </term>
    </president>
    
    <president>
        <number>10</number>
        <name>John Tyler</name>       
        <birthday>1790-03-29</birthday>
        <took_office>1841-04-04</took_office>
        <left_office>1845-03-04</left_office>
        <party>Whig</party>
        <term>
            <number>14</number>
            <vice_president>None</vice_president>
        </term>
    </president>
    
    <president>
        <number>11</number>
        <name>James K. Polk</name>
        <birthday>1795-11-02</birthday>
        <took_office>1845-03-04</took_office>
        <left_office>1849-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>15</number>
            <vice_president>George M. Dallas</vice_president>
        </term>
    </president>
    
    <president>
        <number>12</number>
        <name>Zachary Taylor</name>
        <birthday>1784-11-24</birthday>
        <took_office>1849-03-04</took_office>
        <left_office>1850-07-09</left_office>
        <party>Whig</party>
        <term>
            <number>16</number>
            <vice_president>Millard Fillmore</vice_president>
        </term>
    </president>
    
    <president>
        <number>13</number>
        <name>Millard Fillmore</name>
        <birthday>1800-01-07</birthday>
        <took_office>1850-07-09</took_office>
        <left_office>1853-03-04</left_office>
        <party>Whig</party>
        <term>
            <number>16</number>
            <vice_president>None</vice_president>
        </term>
    </president>
    
    <president>
        <number>14</number>
        <name>Franklin Pierce</name>
        <birthday>1804-11-23</birthday>
        <took_office>1853-03-04</took_office>
        <left_office>1857-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>17</number>
            <vice_president>William R. King</vice_president>
        </term>
    </president>
    
    <president>
        <number>15</number>
        <name>James Buchanan</name>
        <birthday>1791-04-23</birthday>
        <took_office>1857-03-04</took_office>
        <left_office>1861-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>18</number>
            <vice_president>John C. Breckinridge</vice_president>
        </term>
    </president>
    
    <president>
        <number>16</number>
        <name>Abraham Lincoln</name>
        <birthday>1809-02-12</birthday>
        <took_office>1861-03-04</took_office>
        <left_office>1865-04-15</left_office>
        <party>Republican</party>
        <term>
            <number>19</number>
            <vice_president>Hannibal Hamlin</vice_president>
        </term>
        <term>
            <number>20</number>
            <vice_president>Andrew Johnson</vice_president>
        </term>
    </president>
    
    <president>
        <number>17</number>
        <name>Andrew Johnson</name>
        <birthday>1808-12-29</birthday>
        <took_office>1865-04-15</took_office>
        <left_office>1869-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>20</number>
            <vice_president>None</vice_president>
        </term>
    </president>
    
    <president>
        <number>18</number>
        <name>Ulysses S. Grant</name>
        <birthday>1822-04-27</birthday>
        <took_office>1869-03-04</took_office>
        <left_office>1877-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>21</number>
            <vice_president>Schuyler Colfax</vice_president>
        </term>
        <term>
            <number>22</number>
            <vice_president>Henry Wilson</vice_president>
        </term>
    </president>

    <president>
        <number>19</number>
        <name>Rutherford B. Hayes</name>
        <birthday>1822-10-04</birthday>
        <took_office>1877-03-04</took_office>
        <left_office>1881-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>23</number>
            <vice_president>William A. Wheeler</vice_president>
        </term>
    </president>

    <president>
        <number>20</number>
        <name>James A. Garfield</name>
        <birthday>1831-11-19</birthday>
        <took_office>1881-03-04</took_office>
        <left_office>1881-09-19</left_office>
        <party>Republican</party>
        <term>
            <number>24</number>
            <vice_president>Chester A. Arthur</vice_president>
        </term>
    </president>

    <president>
        <number>21</number>
        <name>Chester A. Arthur</name>
        <birthday>1830-10-05</birthday>
        <took_office>1881-09-19</took_office>
        <left_office>1885-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>24</number>
            <vice_president>None</vice_president>
        </term>
    </president>

    <president>
        <number>22</number>
        <name>Grover Cleveland</name>
        <birthday>1837-03-18</birthday>
        <took_office>1885-03-04</took_office>
        <left_office>1889-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>25</number>
            <vice_president>Thomas A. Hendricks</vice_president>
        </term>
    </president>

    <president>
        <number>23</number>
        <name>Benjamin Harrison</name>
        <birthday>1833-08-20</birthday>
        <took_office>1889-03-04</took_office>
        <left_office>1893-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>26</number>
            <vice_president>Levi P. Morton</vice_president>
        </term>
    </president>
    
    <president>
        <number>24</number>
        <name>Grover Cleveland</name>
        <birthday>1837-03-18</birthday>
        <took_office>1893-03-04</took_office>
        <left_office>1897-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>27</number>
            <vice_president>Adlai Stevenson I</vice_president>
        </term>
    </president>

    <president>
        <number>25</number>
        <name>William McKinley</name>
        <birthday>1843-01-29</birthday>
        <took_office>1897-03-04</took_office>
        <left_office>1901-09-14</left_office>
        <party>Republican</party>
        <term>
            <number>28</number>
            <vice_president>Garret Hobart</vice_president>
        </term>
        <term>
            <number>29</number>
            <vice_president>Theodore Roosevelt</vice_president>
        </term>
    </president>
    
    <president>
        <number>26</number>
        <name>Theodore Roosevelt</name>
        <birthday>1858-10-27</birthday>
        <took_office>1901-09-14</took_office>
        <left_office>1909-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>29</number>
            <vice_president>None</vice_president>
        </term>
        <term>
            <number>30</number>
            <vice_president>Charles W. Fairbanks</vice_president>
        </term>
    </president>

    <president>
        <number>27</number>
        <name>William Howard Taft</name>
        <birthday>1857-09-15</birthday>
        <took_office>1909-03-04</took_office>
        <left_office>1913-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>31</number>
            <vice_president>James S. Sherman</vice_president>
        </term>
    </president>
    
    <president>
        <number>28</number>
        <name>Woodrow Wilson</name>
        <birthday>1856-12-28</birthday>
        <took_office>1913-03-04</took_office>
        <left_office>1921-03-04</left_office>
        <party>Democratic</party>
        <term>
            <number>32</number>
            <vice_president>Thomas R. Marshall</vice_president>
        </term>
    </president>
    
    <president>
        <number>29</number>
        <name>Warren G. Harding</name>
        <birthday>1865-11-02</birthday>
        <took_office>1921-03-04</took_office>
        <left_office>1923-08-02</left_office>
        <party>Republican</party>
        <term>
            <number>34</number>
            <vice_president>Calvin Coolidge</vice_president>
        </term>
    </president>
    
    <president>
        <number>30</number>
        <name>Calvin Coolidge</name>
        <birthday>1872-07-04</birthday>
        <took_office>1923-08-02</took_office>
        <left_office>1929-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>35</number>
            <vice_president>Charles G. Dawes</vice_president>
        </term>
    </president>
    
    <president>
        <number>31</number>
        <name>Herbert Hoover</name>
        <birthday>1874-08-10</birthday>
        <took_office>1929-03-04</took_office>
        <left_office>1933-03-04</left_office>
        <party>Republican</party>
        <term>
            <number>36</number>
            <vice_president>Charles Curtis</vice_president>
        </term>
    </president>
    
    <president>
        <number>32</number>
        <name>Franklin D. Roosevelt</name>
        <birthday>1882-01-30</birthday>
        <took_office>1933-03-04</took_office>
        <left_office>1945-04-12</left_office>
        <party>Democratic</party>
        <term>
            <number>37</number>
            <vice_president>John Nance Gardner</vice_president>
        </term>
        <term>
            <number>38</number>
            <vice_president>John Nance Gardner</vice_president>
        </term>
        <term>
            <number>39</number>
            <vice_president>Henry A. Wallace</vice_president>
        </term>
        <term>
            <number>40</number>
            <vice_president>Harry S. Truman</vice_president>
        </term>
    </president>
    
    <president>
        <number>33</number>
        <name>Harry S. Truman</name>
        <birthday>1884-05-08</birthday>
        <took_office>1945-04-12</took_office>
        <left_office>1953-01-20</left_office>
        <party>Democratic</party>
        <term>
            <number>40</number>
            <vice_president>None</vice_president>
        </term>
        <term>
            <number>41</number>
            <vice_president>Alben W. Barkley</vice_president>
        </term>
    </president>
    
    <president>
        <number>34</number>
        <name>Dwight D. Eisenhower</name>
        <birthday>1890-10-14</birthday>
        <took_office>1953-01-20</took_office>
        <left_office>1961-01-20</left_office>
        <party>Republican</party>
        <term>
            <number>42</number>
            <vice_president>Richard Nixon</vice_president>
        </term>
        <term>
            <number>43</number>
            <vice_president>Richard Nixon</vice_president>
        </term>
    </president>
    
    <president>
        <number>35</number>
        <name>John F. Kennedy</name>
        <birthday>1917-05-29</birthday>
        <took_office>1961-01-20</took_office>
        <left_office>1963-11-22</left_office>
        <party>Democratic</party>
        <term>
            <number>44</number>
            <vice_president>Lyndon B. Johnson</vice_president>
        </term>
    </president>
    
    <president>
        <number>36</number>
        <name>Lyndon B. Johnson</name>
        <birthday>1908-08-27</birthday>
        <took_office>1963-11-22</took_office>
        <left_office>1969-01-20</left_office>
        <party>Democratic</party>
        <term>
            <number>44</number>
            <vice_president>None</vice_president>
        </term>
        <term>
            <number>45</number>
            <vice_president>Hubert Humphrey</vice_president>
        </term>
    </president>
    
    <president>
        <number>37</number>
        <name>Richard Nixon</name>
        <birthday>1913-01-09</birthday>
        <took_office>1969-01-20</took_office>
        <left_office>1974-08-09</left_office>
        <party>Republican</party>
        <term>
            <number>46</number>
            <vice_president>Spiro Agnew</vice_president>
        </term>
        <term>
            <number>47</number>
            <vice_president>Gerald Ford</vice_president>
        </term>
    </president>
    
    <president>
        <number>38</number>
        <name>Gerald Ford</name>
        <birthday>1913-07-14</birthday>
        <took_office>1974-08-09</took_office>
        <left_office>1977-01-20</left_office>
        <party>Republican</party>
        <term>
            <number>47</number>
            <vice_president>Nelson Rockefeller</vice_president>
        </term>
    </president>
    
    <president>
        <number>39</number>
        <name>Jimmy Carter</name>
        <birthday>1924-10-01</birthday>
        <took_office>1977-01-20</took_office>
        <left_office>1981-01-20</left_office>
        <party>Democratic</party>
        <term>
            <number>48</number>
            <vice_president>Walter Mondale</vice_president>
        </term>
    </president>
    
    <president>
        <number>40</number>
        <name>Ronald Reagan</name>
        <birthday>1911-02-06</birthday>
        <took_office>1981-01-20</took_office>
        <left_office>1989-01-20</left_office>
        <party>Republican</party>
        <term>
            <number>49</number>
            <vice_president>George H. W. Bush</vice_president>
        </term>
        <term>
            <number>50</number>
            <vice_president>George H. W. Bush</vice_president>
        </term>
    </president>
    
    <president>
        <number>41</number>
        <name>George H. W. Bush</name>
        <birthday>1924-06-12</birthday>
        <took_office>1989-01-20</took_office>
        <left_office>1993-01-20</left_office>
        <party>Republican</party>
        <term>
            <number>51</number>
            <vice_president>Dan Quayle</vice_president>
        </term>
    </president>
    
    <president>
        <number>42</number>
        <name>Bill Clinton</name>
        <birthday>1946-08-19</birthday>
        <took_office>1993-01-20</took_office>
        <left_office>2001-01-20</left_office>
        <party>Democratic</party>
        <term>
            <number>52</number>
            <vice_president>Al Gore</vice_president>
        </term>
        <term>
            <number>53</number>
            <vice_president>Al Gore</vice_president>
        </term>
    </president>
    
    <president>
        <number>43</number>
        <name>George W. Bush</name>
        <birthday>1946-07-06</birthday>
        <took_office>2001-01-20</took_office>
        <left_office>2009-01-20</left_office>
        <party>Republican</party>
        <term>
            <number>54</number>
            <vice_president>Dick Cheney</vice_president>
        </term>
        <term>
            <number>55</number>
            <vice_president>Dick Cheney</vice_president>
        </term>
    </president>
    
    <president>
        <number>44</number>
        <name>Barack Obama</name>
        <birthday>1961-08-04</birthday>
        <took_office>2009-01-20</took_office>
        <left_office>Incumbent</left_office>
        <party>Democratic</party>
        <term>
            <number>56</number>
            <vice_president>Joe Biden</vice_president>
        </term>
    </president>
</presidents>

Last edited by kaminel; October 10th, 2014 at 11:38 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
I have inserted images in a folder but i am unable to retrive images from it jayantsupercop Beginning PHP 0 February 17th, 2014 09:46 AM
Adding Text to Image Uploaded to Folder hemo ASP.NET 3.5 Basics 0 June 23rd, 2011 06:27 AM
Get images from folder surendran ActionScript 1 December 12th, 2007 11:55 PM
xslt adding image palli2004 XSLT 2 December 30th, 2006 06:35 PM
images folder Lee jonesy Dreamweaver (all versions) 7 September 12th, 2004 01:35 PM





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