2015-09-23 27 views
0

好吧,我試圖顯示每個段落的圖像,而顯示出來的圖像只是左上角的x。有人能解釋我做錯了什麼嗎?xslt中的圖像顯示爲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

您有混合的HTML標籤'img'用'image' ? –

回答

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> 

然後將零件取出結束標記</img>

+0

好吧我試過它仍然做同樣的事情 – kfreeman04208

+0

@ kfreeman04208對不起,它應該是'img',而不是'image'。如果仍然不起作用 - 即您的輸出顯示「」,但圖像未呈現,則需要將路徑調整到圖像實際所在的位置。 –

+0

好吧我猜我不明白。是不是main_image/@文件的位置圖片?我也嘗試了古代的想法/ wonder/main_image/@文件。依然沒有。 – kfreeman04208

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

好吧,我假設出於某種原因,視覺工作室不能夠檢索圖像。我是否需要將圖像添加爲資源?或者他們只能在文件所在的文件夾中? – kfreeman04208

+0

@ kfreeman04208 - 抱歉,我沒有使用visual studio。 –