所以我有一个XML文档和一个XSL样式表。我正在循环通过我的一个元素,并试图显示表中的所有元素-它显示了表的"存根"的正确数量,但没有文本。有人能帮忙吗?
这是我的XML文档:
<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/xsl" href="xrt.xsl"?>
<Inventory>
<DatabaseName>
<GlobalName>Tom</GlobalName>
<Function>production</Function>
<Domain>tom.info</Domain>
<Administrator EmailAlias="xrichards" Extension="221">Xavier Richards</Administrator>
<Attributes Type="Production" Version="20ix"/>
<Comments>
...
</Comments>
<Usage>
500
</Usage>
</DatabaseName>
<WebserverName>
<GlobalName>Jim</GlobalName>
<Function>distribution</Function>
<Domain>jim1235.com</Domain>
<Administrator EmailAlias="rknowles" Extension="134237">Richard Knowles</Administrator>
<Administrator EmailAlias="thoffman" Extension="222237">Tom Hoffman</Administrator>
<Attributes Type="Production" Version="20ix"/>
<Comments>
...
</Comments>
<Usage>
1200
</Usage>
</WebserverName>
</Inventory>
这是我的XSL样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>The Inventory</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!--DatabaseName Template-->
<xsl:template match="Inventory/DatabaseName">
<h2><xsl:value-of select="GlobalName"/></h2>
<xsl:choose>
<xsl:when test="Usage >= 500">
<p>Its function is <xsl:value-of select="Function"/> and its domain is <xsl:value-of select="Domain"/>. The database is widely used.</p>
<h3>Administrators</h3>
<table border="1">
<tbody>
<xsl:for-each select="Administrator">
<tr>
<td>
<xsl:value-of select="Administrator"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:when>
<xsl:otherwise>
<p>Its function is <xsl:value-of select="Function"/> and its domain is <xsl:value-of select="Domain"/>. The database is not used widely.</p>
<h3>Administrators</h3>
<table border="1">
<tbody>
<xsl:for-each select="Administrator">
<tr>
<td>
<xsl:value-of select="Administrator"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--WebserverName Template-->
<xsl:template match="WebserverName">
<h2><xsl:value-of select="GlobalName"/></h2>
<xsl:choose>
<xsl:when test="Usage >= 1000">
<p>Its function is <xsl:value-of select="Function"/> and its domain is <xsl:value-of select="Domain"/>. The webserver is widely used.</p>
<h3>Administrators</h3>
<table border="1">
<tbody>
<xsl:for-each select="Administrator">
<tr>
<td>
<xsl:value-of select="Administrator"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:when>
<xsl:otherwise>
<p>Its function is <xsl:value-of select="Function"/> and its domain is <xsl:value-of select="Domain"/>. The webserver is not used widely.</p>
<h3>Administrators</h3>
<xsl:for-each select="Administrator">
<table border="1">
<tbody>
<xsl:for-each select="Administrator">
<tr>
<td>
<xsl:value-of select="Administrator"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<xsl:for-each select="Administrator">
将您置于Administrator
的上下文中。从这个上下文中,
<xsl:value-of select="Administrator"/>
不选择任何内容,因为上下文节点没有名为Administrator的子节点。您应该使用:
<xsl:value-of select="."/>
与你的问题无关,但你不应该重复相同的代码两次(或更多)-参见:https://en.wikipedia.org/wiki/Don%27t_repeat_yourself