好吧我们试图显示每个段落的图像,而是显示我得到的图像是左上角的x。有人可以解释一下我做错了吗?
这是XML
<?xml version="1.0"?>
<!-- Note: For many of the wonders, the experts do not agree on precise dates or construction dimensions. In these cases, I chose a year or dimension in the middle of the range so all attributes could be numeric. -->
<ancient_wonders>
<wonder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Mod2Lab2solution.xsd">
<name language="English">Colossus of Rhodes</name>
<name language="Greek">Κολοσσός της Ρόδου</name>
<location>Rhodes, Greece</location>
<height units="feet">107</height>
<history>
<year_built era="BC">282</year_built>
<year_destroyed era="BC">226</year_destroyed>
<how_destroyed>earthquake</how_destroyed>
<story>
In 294 BC, the people of the island of Rhodes began building a colossal statue of the sun god Helios. They believed that it was because of his blessings that they were able to withstand a long siege on the island and emerge victorious.<para/>The Colossus was built with bronze, reinforced with iron, and weighted with stones. While it is often depicted straddling Mandrákion harbor, this is now considered technically impossible; and therefore, it likely stood beside the harbor.<para/>The statue was toppled by an earthquake in 226 BC. It snapped at the knees and fell over on to the land. The Oracle of Delphi suggested that it fell because the people of Rhodes had offended Helios, and they decided not to rebuild it.<para/>The statue remained on the ground until 654 AD., and even broken, it was so impressive that many traveled to see it.
</story>
</history>
<main_image file="colossus.jpg" w="528" h="349"/>
<source sectionid="101" newspaperid="21"/>
</wonder>
<wonder>
<name language="English">Great Pyramid of Giza</name>
<location>Giza, Egypt</location>
<height units="feet">455</height>
<history>
<year_built era="BC">2570</year_built>
<story>
It is believed to have taken 20 years and as many as 100,000 workers to complete the Great Pyramid, which was built as a tomb for the 4th dynasty Egyptian pharaoh named Khufu. It was built as part of a complex that included temples and many other pyramids.<para/>The outermost stones of the pyramid were highly polished white limestone, which were eventually loosened by an earthquake more than 600 years ago, and were removed to help build cities and mosques. When these casing stones were present, some believe that the pyramid was so large and bright that it could be seen from the moon.<para/>There is much speculation about the construction methodologies and intentions of the pyramid, including references to the moon, the Orion constellation, continental gravity, and more. What is known, however, is that the four sides of the base are more than 700 feet long, and differ in length by no more than 8 inches. Each side of the pyramid is almost perfectly aligned with the four cardinal points of the compass. And, the pyramid's dimensions covert to a ratio that equates to 2π with nearly perfect accuracy.
</story>
</history>
<main_image file="pyramid.jpg" w="528" h="349"/>
<source sectionid="123" newspaperid="71"/>
<source sectionid="21" newspaperid="42"/>
</wonder>
<wonder>
<name language="English">Hanging Gardens of Babylon</name>
<location>Al Hillah, Iraq</location>
<height units="feet">0</height>
<history>
<year_built era="BC">600</year_built>
<year_destroyed era="BC">226</year_destroyed>
<how_destroyed>earthquake</how_destroyed>
<story>
The first and most interesting fact about the gardens is that there is significant controversy about whether the gardens existed at all.<para/>Whether they did or did not exist, there are many elaborate accounts and poetic descriptions of the gardens. They are generally believed to have been built by King Nebuchadrezzar II for his wife because she missed the gardens of her home. Some research suggests that it was an elaborate series of rooftop gardens. Another theory suggests that the gardens were built in the walls of the royal palace.<para/>Babylon, being in the middle of the desert, had no such natural greenery, however; calling into question of how such lushness would have survived in the dryness of the desert. Recent excavations have suggested the use of an exceptional system of irrigation using a cellar well in conjunction with a chain pump to raise the water to the gardens. Still, other theories even suggest that the gardens weren't in Babylon at all. Rather, that they were constructed by Sennacherib at the eastern bank of the Tigris river.<para/>Regardless of the final outcome, it is interesting to note that the imagination of the poets and ancient historians have created one of the Wonders of the World.
</story>
</history>
<main_image file="gardens.jpg" w="528" h="349"/>
<source sectionid="11" newspaperid="24"/>
<source sectionid="18" newspaperid="151"/>
</wonder>
<wonder>
<name language="English">Statue of Zeus at Olympia</name>
<name language="Greek">Δίας μυθολογία</name>
<location>Olympia, Greece</location>
<height units="feet">39</height>
<history>
<year_built era="BC">430</year_built>
<year_destroyed era="AD">426</year_destroyed>
<how_destroyed>fire</how_destroyed>
<story>Carved from ivory, on a throne of cedarwood, the statue was created by the Greek sculptor Phidias around 430 BC. In its right hand was a life-size statue of Nike, the goddess of victory, and in its left was a large sceptre topped with an eagle. The statue, nearly 40 feet tall, was said to fill the entire width of the one of the aisles of the Temple of Zeus, and its head nearly scraped the temple's ceiling.<para/>In 426 AD, the temple was destroyed and many historians believe that the statue was destroyed at that time. Others believe, however, that the statue was moved to Constantinople (now Istanbul) and was destroyed about 50 years later.<para/>Although many copies of the statue were made during its 800+ year lifespan, none are known to have survived.</story>
</history>
<main_image file="zeus.jpg" w="528" h="349"/>
</wonder>
<wonder>
<name language="English">Temple of Artemis at Ephesus</name>
<name language="Greek">Ἀρτεμίσιον</name>
<location>Ephesus, Turkey</location>
<height units="feet">60</height>
<history>
<year_built era="BC">550</year_built>
<year_destroyed era="BC">356</year_destroyed>
<how_destroyed>fire</how_destroyed>
<story>The Temple of Artemis at Ephesus was built and rebuilt over the course of many years. The most famous was built in about 550 BC and was funded by King Croesus of Lydia.<para/>Unlike many other temples of its time, it was built of marble and glittered with gold. The temple's foundation was over 180 by 350 feet and its steps led to a high platform on which stood more than one hundred beautifully sculptured columns that supported its roof. At least twice the size of the Parthenon, it was so breathtaking it was said to rise to the clouds.<para/>The temple housed many incredible works of art, but the most famous was the statue of Artemis herself. Although the original no longer exists, it was thought to have been made of gold and other beautiful materials. Her legs were covered with animals and bees and the top of the body covered with breasts symbolizing fertility.<para/>Although destroyed and rebuilt many times, and ultimately left to be destroyed by man, nature and neglect, the most famous version of the temple was destroyed by arson committed by a man named Herostratus on the night Alexander the Great was born.</story>
</history>
<main_image file="artemis.jpg" w="528" h="349"/>
<source sectionid="92" newspaperid="19"/>
</wonder>
<wonder>
<name language="English">Mausoleum at Halicarnassus</name>
<name language="Greek">Μαυσωλεῖον Ἁλικαρνασσεύς</name>
<location>Bodrum, Turkey</location>
<height units="feet">135</height>
<history>
<year_built era="BC">352</year_built>
<year_destroyed era="AD">1404</year_destroyed>
<how_destroyed>earthquake</how_destroyed>
<story>The monument was built as a tomb for Mausolus, a governor in the Persian Empire. Sparing no expense, his widowed wife Artemisia (who was also his sister as was considered customary) commissioned well-known Greek architects and artists to design the tomb and sculptural reliefs for each of the four sides of the building.<para/>The monument was almost square, nearly 14 stories tall, and its base was more than 10,000 square feet. Each side of the tomb had nine massive columns, and the top was a stepped pyramid on which stood by a four-horse marble chariot in which there were images of Mausolus and Artemisia.<para/>The monument stood for nearly 17 centuries and was eventually destroyed by a series of earthquakes. And, like the Lighthouse of Alexandria, the tomb was so famous that Mausolus's name has become the root word for large tombs in many languages (for example, "mausoleo" in Spanish).</story>
</history>
<main_image file="mausoleum.jpg" w="528" h="349"/>
<source sectionid="141" newspaperid="21"/>
<source sectionid="2" newspaperid="19"/>
</wonder>
<wonder>
<name language="English">Lighthouse of Alexandria</name>
<name language="Greek">ὁ Φάρος τῆς Ἀλεξανδρείας</name>
<location>Alexandria, Egypt</location>
<height units="feet">384</height>
<history>
<year_built era="BC">280</year_built>
<year_destroyed era="AD">1323</year_destroyed>
<how_destroyed>earthquake</how_destroyed>
<story>
Located on the island of Pharos in the harbor of Alexandria, the lighthouse may be the most famous lighthouse in history. The lighthouse was very different than modern lighthouses in that it was built in three stages, all sloping inward. Built of marble blocks with lead mortar; the lowest was square, the next octagonal, and the top cylindrical. Within the lighthouse was a ramp and "dumbwaiter" that allowed wood to be transported to the fire that burned at night.<para/>Inside the open top of the lighthouse was a large curved mirror that was used to reflect the sunlight during the day and the fire at night. It is said that mariners could see the light up to 35 miles away. Legends have it that the light was so bright it could be used to burn enemy ships.<para/>There are many stories about its ultimate demise, however, the most likely cause is believed to be as many as 22 earthquakes between 320 AD and 1323 AD which led to its decommission.<para/>The Lighthouse of Alexandria was so famous in ancient times that the island on which it stood, Pharos, became the root word for lighthouse in many languages (for example, "phare" in French).
</story>
</history>
<main_image file="lighthouse.jpg" w="528" h="349"/>
<source sectionid="112" newspaperid="53"/>
</wonder>
</ancient_wonders>
这是XSLT
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<!-- ** XML2e ** -->
<!-- to follow the book's example, see this and the sections below -->
<xsl:template match="/">
<html>
<head>
<title>Wonders of the World</title>
</head>
<body>
<h1>Seven Wonders of the Ancient World</h1>
<h2>Overview</h2>
<table border="1">
<tr>
<th>Wonder Name</th>
<th>Location</th>
<th>Height</th>
</tr>
<!-- ** XML2e ** -->
<!-- to follow the book's example, see this and the sections below -->
<xsl:apply-templates select="/ancient_wonders/wonder[position()=last]">
<xsl:sort select="height" order="descending" data-type="number" />
</xsl:apply-templates>
</table>
<h2>History</h2>
<xsl:apply-templates select="ancient_wonders/wonder/history">
<xsl:sort select="year_built" order="descending" data-type="number" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<!-- ** XML2e ** -->
<!-- to follow the book's example, see this and the sections below -->
<xsl:template match="wonder">
<tr>
<td>
<a>
<xsl:attribute name="href">
#<xsl:value-of select="name[@language='English']"/>
</xsl:attribute>
<strong>
<xsl:value-of select="name[@language='English']"/>
</strong>
</a>
<br/>
<!-- ** XML2e ** -->
<!-- to follow the book's example, see this and the sections below -->
<xsl:apply-templates select="name[@language!='English']"/>
</td>
<td>
<xsl:value-of select="location"/>
</td>
<td>
<xsl:choose>
<xsl:when test="height != 0">
<xsl:value-of select="height"/>
</xsl:when>
<xsl:otherwise>
unknown
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
<!-- ** XML2e ** -->
<!-- to follow the book's example, see this section below -->
<xsl:template match="name[@language!='English']">
(<em>
<xsl:value-of select="."/>
</em>)
</xsl:template>
<xsl:template match="history">
<a>
<xsl:attribute name="name">
<xsl:value-of select="../name[@language='English']" />
</xsl:attribute>
</a>
<image>
<xsl:attribute name="src">
<xsl:value-of select="wonder/main_image/@file"/>
The <xsl:value-of select="../name[@language='English']"/>
<xsl:apply-templates select="../name[@language='English']"/>
was built in <xsl:value-of select="year_built"/>
<xsl:text>
</xsl:text><xsl:value-of select="year=built/@era"/>
</xsl:attribute>
</image>
<xsl:choose>
<xsl:when test="year_destroyed !=0">
and was destroyed by <xsl:value-of select="how_destroyed"/>
in <xsl:value-of select="year_destroyed"/> <xsl:text></xsl:text>
<xsl:value-of select="year_destroyed/@era"/>
</xsl:when>
<xsl:otherwise>
and is still standing today.
</xsl:otherwise>
</xsl:choose>
<br /><br />
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
尝试更改此部分:
<image>
<xsl:attribute name="src">
<xsl:value-of select="wonder/main_image/@file"/>
The <xsl:value-of select="../name[@language='English']"/>
<xsl:apply-templates select="../name[@language='English']"/>
was built in <xsl:value-of select="year_built"/>
<xsl:text>
</xsl:text><xsl:value-of select="year=built/@era"/>
</xsl:attribute>
</image>
为:
<img>
<xsl:attribute name="src">
<xsl:value-of select="../main_image/@file"/>
</xsl:attribute>
</img>
然后在<{strong> </img>
结束标记之后添加取出的部分。
答案 1 :(得分:1)
创建image
(或img
)时,您的上下文为history
。这意味着您只需要上一个父级别即可访问main_image
:../main_image/@file
使用AVT ...
进行简化的示例<img src="{../main_image/@file}"/>
这至少可以获得@file
的价值。根据实际的图像位置,您可能需要添加路径。
以下是一个工作示例:http://xsltransform.net/jyRYYhP
它有其他可能或可能不是您想要的更改,但可能是一个更好的起点。
长寿的例子代码......
XSLT 1.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<head>
<title>Wonders of the World</title>
</head>
<body>
<h1>Seven Wonders of the Ancient World</h1>
<h2>Overview</h2>
<table border="1">
<tr>
<th>Wonder Name</th>
<th>Location</th>
<th>Height</th>
</tr>
<xsl:apply-templates select="/ancient_wonders/wonder">
<xsl:sort select="height" order="descending" data-type="number" />
</xsl:apply-templates>
</table>
<h2>History</h2>
<xsl:apply-templates select="ancient_wonders/wonder/history">
<xsl:sort select="year_built" order="descending" data-type="number" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="wonder">
<tr>
<td>
<xsl:apply-templates select="name"/>
</td>
<td>
<xsl:apply-templates select="location"/>
</td>
<td>
<xsl:apply-templates select="height"/>
</td>
</tr>
</xsl:template>
<xsl:template match="height[.=0]">
<xsl:text>unknown</xsl:text>
</xsl:template>
<xsl:template match="name[@language!='English']">
<br/>
<xsl:text>(</xsl:text>
<em><xsl:value-of select="."/></em>
<xsl:text>)</xsl:text>
</xsl:template>
<xsl:template match="name">
<a href="#{.}">
<strong>
<xsl:value-of select="."/>
</strong>
</a>
</xsl:template>
<xsl:template match="history">
<a name="{../name[@language='English']}"/>
<img src="{../main_image/@file}"/>
<xsl:text>The </xsl:text>
<xsl:value-of select="../name[@language='English']"/>
<xsl:text> was built in </xsl:text>
<xsl:value-of select="year_built"/>
<xsl:choose>
<xsl:when test="year_destroyed !=0">
<xsl:text> and was destroyed by </xsl:text>
<xsl:value-of select="how_destroyed"/>
<xsl:text> in </xsl:text>
<xsl:value-of select="year_destroyed"/>
<xsl:text> </xsl:text>
<xsl:value-of select="year_destroyed/@era"/>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> and is still standing today.</xsl:text>
</xsl:otherwise>
</xsl:choose>
<br /><br />
</xsl:template>
</xsl:stylesheet>
HTML输出
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Wonders of the World</title>
</head>
<body>
<h1>Seven Wonders of the Ancient World</h1>
<h2>Overview</h2>
<table border="1">
<tr>
<th>Wonder Name</th>
<th>Location</th>
<th>Height</th>
</tr>
<tr>
<td><a href="#Great Pyramid of Giza"><strong>Great Pyramid of Giza</strong></a></td>
<td>Giza, Egypt</td>
<td>455</td>
</tr>
<tr>
<td><a href="#Lighthouse of Alexandria"><strong>Lighthouse of Alexandria</strong></a><br>(<em>ὁ Φάρος τῆς Ἀλεξανδρείας</em>)
</td>
<td>Alexandria, Egypt</td>
<td>384</td>
</tr>
<tr>
<td><a href="#Mausoleum at Halicarnassus"><strong>Mausoleum at Halicarnassus</strong></a><br>(<em>Μαυσωλεῖον Ἁλικαρνασσεύς</em>)
</td>
<td>Bodrum, Turkey</td>
<td>135</td>
</tr>
<tr>
<td><a href="#Colossus of Rhodes"><strong>Colossus of Rhodes</strong></a><br>(<em>Κολοσσός της Ρόδου</em>)
</td>
<td>Rhodes, Greece</td>
<td>107</td>
</tr>
<tr>
<td><a href="#Temple of Artemis at Ephesus"><strong>Temple of Artemis at Ephesus</strong></a><br>(<em>Ἀρτεμίσιον</em>)
</td>
<td>Ephesus, Turkey</td>
<td>60</td>
</tr>
<tr>
<td><a href="#Statue of Zeus at Olympia"><strong>Statue of Zeus at Olympia</strong></a><br>(<em>Δίας μυθολογία</em>)
</td>
<td>Olympia, Greece</td>
<td>39</td>
</tr>
<tr>
<td><a href="#Hanging Gardens of Babylon"><strong>Hanging Gardens of Babylon</strong></a></td>
<td>Al Hillah, Iraq</td>
<td>unknown</td>
</tr>
</table>
<h2>History</h2><a name="Great Pyramid of Giza"></a><img src="pyramid.jpg">The Great Pyramid of Giza was built in 2570 and is still standing today.<br><br><a name="Hanging Gardens of Babylon"></a><img src="gardens.jpg">The Hanging Gardens of Babylon was built in 600 and was destroyed by earthquake in 226 BC.<br><br><a name="Temple of Artemis at Ephesus"></a><img src="artemis.jpg">The Temple of Artemis at Ephesus was built in 550 and was destroyed by fire in 356 BC.<br><br><a name="Statue of Zeus at Olympia"></a><img src="zeus.jpg">The Statue of Zeus at Olympia was built in 430 and was destroyed by fire in 426 AD.<br><br><a name="Mausoleum at Halicarnassus"></a><img src="mausoleum.jpg">The Mausoleum at Halicarnassus was built in 352 and was destroyed by earthquake in 1404 AD.<br><br><a name="Colossus of Rhodes"></a><img src="colossus.jpg">The Colossus of Rhodes was built in 282 and was destroyed by earthquake in 226 BC.<br><br><a name="Lighthouse of Alexandria"></a><img src="lighthouse.jpg">The Lighthouse of Alexandria was built in 280 and was destroyed by earthquake in 1323 AD.<br><br></body>
</html>