我有两个文件:groundup.xml和groundup.xslt。
groundup.xml:
<content>
<root>
<housing_option_name>The first name</housing_option_name>
<housing_option_headline>Live under a desk</housing_option_headline>
<housing_option_address>Kinda behind the Shell gas station</housing_option_address>
<include_description>true</include_description>
<description_images>/uploadedImages/RecSports/Intramural_Sports/Photos/Basketball 055.jpg</description_images>
<description_images>/uploadedImages/StudyAbroad/Slideshow/Adamwood.jpg</description_images>
<room_types_and_layouts>Here you can sleep. Here you eat.</room_types_and_layouts>
<include_virtual_room_tour>false</include_virtual_room_tour>
<include_photos>true</include_photos>
</root>
<root>
<housing_option_name>A real housing option</housing_option_name>
<housing_option_headline>where fun comes to multiply</housing_option_headline>
<housing_option_address>
The address goes here
</housing_option_address>
<include_description>false</include_description>
<description_images>/uploadedImages/bg_mural_Partner_for_Success.jpg</description_images>
<room_types_and_layouts>Some text about room types and layouts.</room_types_and_layouts>
<include_virtual_room_tour>false</include_virtual_room_tour>
<include_photos>true</include_photos>
</root>
</content>
和groundup.xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<html>
<body>
<div id="residence_halls">
<ul>
<xsl:for-each select="content/root">
<div>
<xsl:attribute name="id">
<xsl:value-of select="translate(housing_option_name, ' ', '_')"/>
</xsl:attribute>
<xsl:value-of select="content/root/housing_option_name"/>
</div>
</xsl:for-each>
</ul>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我设法将housing_option_name放入id字段,但是,我仍然试图让housing_option_name在最终的html中显示为文本。现在我只看到一个空白的屏幕,但是查看最终的源代码,有两个div,其中有ids为housing_option_name,但div中没有文字。
我在这里缺少什么?
编辑:最终的html如下所示:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="residence_halls">
<div id="The_first_name">
</div>
<div id="A_real_housing_option">
</div>
</div>
</body>
</html>
编辑:为了简洁而拿出uls
答案 0 :(得分:1)
<xsl:value-of select="housing_option_name"/>
当然?既然你已经在内容/根路径上的for-each中了?