每个循环的 XSL 通过我的 XML table - 显示 table 存根但没有文本
XSL for each loops through my XML table - shows the table stubs but no text
所以我有一个 XML 文档和一个 XSL 样式表。我正在遍历我的一个元素并尝试显示 table 中的所有元素 - 它显示 table 的 'stubs' 的正确数量但没有文本。有人可以帮忙吗?
这是我的 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
所以我有一个 XML 文档和一个 XSL 样式表。我正在遍历我的一个元素并尝试显示 table 中的所有元素 - 它显示 table 的 'stubs' 的正确数量但没有文本。有人可以帮忙吗?
这是我的 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