如何使用 xslt 显示备用 xml 值
How to display an alternate xml value using xslt
使用 v2.0 xsl 样式表,我将 XML 显示为 HTML table。 @required 属性包含“1”值,表示它是必需的。我想在显示的 html table 中将“1”值显示为 "Y" 值,保持源 XML 不变。
示例XML:
<table tableName="ABC" fieldname="field1" required="1" />
示例 XSL 未按预期工作,它显示空白 HTML 页面:
<td><xsl:value-of select="(@required, '1', 'Y')"/></td>
请指教。谢谢!
假设输入 XML 是
<table tableName="ABC" fieldname="field1" required="1" />
并且需要以表格形式打印属性,可以使用如下XSL实现输出。
<xsl:template match="table">
<html>
<body>
<table>
<tr>
<td><xsl:value-of select="@tableName" /></td>
<td><xsl:value-of select="@fieldname" /></td>
<td>
<xsl:choose>
<xsl:when test="@required = '1'">
<xsl:value-of select="'Y'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'N'" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
当@required
为1
时显示Y
,您可以使用<xsl:choose>
,这将允许您在不修改输入的情况下输出所需的值XML数据。
输出
<html>
<body>
<table>
<tr>
<td>ABC</td>
<td>field1</td>
<td>Y</td>
</tr>
</table>
</body>
</html>
使用 v2.0 xsl 样式表,我将 XML 显示为 HTML table。 @required 属性包含“1”值,表示它是必需的。我想在显示的 html table 中将“1”值显示为 "Y" 值,保持源 XML 不变。
示例XML:
<table tableName="ABC" fieldname="field1" required="1" />
示例 XSL 未按预期工作,它显示空白 HTML 页面:
<td><xsl:value-of select="(@required, '1', 'Y')"/></td>
请指教。谢谢!
假设输入 XML 是
<table tableName="ABC" fieldname="field1" required="1" />
并且需要以表格形式打印属性,可以使用如下XSL实现输出。
<xsl:template match="table">
<html>
<body>
<table>
<tr>
<td><xsl:value-of select="@tableName" /></td>
<td><xsl:value-of select="@fieldname" /></td>
<td>
<xsl:choose>
<xsl:when test="@required = '1'">
<xsl:value-of select="'Y'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'N'" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
当@required
为1
时显示Y
,您可以使用<xsl:choose>
,这将允许您在不修改输入的情况下输出所需的值XML数据。
输出
<html>
<body>
<table>
<tr>
<td>ABC</td>
<td>field1</td>
<td>Y</td>
</tr>
</table>
</body>
</html>