如何修复此 xml 和 xsl 代码,因为它不起作用



首先尝试对xml进行编码,并使用xsl进行html输出。

我举了W3的例子,并根据自己的需要对它们进行了修改,但我错过了一些东西,因为在浏览器中查看xml确实可以正常工作。浏览器中没有显示任何html代码,但xml中的项目信息显示为长列表。

浏览器中显示的内容:

SCALARADD Image1inSCALARADD Add one value to an image. A B A same as B allowed redLevel, greenLevel, blueLevel TRIMFILL Image1inTRIMFILL Trim an image and fill the trim area. A B A same as B allowed trimTopIndex, trimBottomIndex, trimLeftIndex, trimRightIndex fillRedLevel, fillGreenLevel, fillBlueLevel

这是xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="routines.xsl"?>
<family>
<Image1in>
<routine>SCALARADD</routine>
<symbolic> Image1inSCALARADD </symbolic>
<operation> Add one value to an image. </operation>
<inputLayer1> A </inputLayer1>
<inputLayer2></inputLayer2>
<outputLayer1> B </outputLayer1>
<commentLayer> A same as B allowed </commentLayer>
<inputLong></inputLong>
<inputDouble> redLevel, greenLevel, blueLevel </inputDouble>
<outputLong></outputLong>
<outputDouble></outputDouble>
<comment>  </comment>
</Image1in>
<Image1in>
<routine>TRIMFILL</routine>
<symbolic> Image1inTRIMFILL </symbolic>
<operation> Trim an image and fill the trim area. </operation>
<inputLayer1> A </inputLayer1>
<inputLayer2></inputLayer2>
<outputLayer1> B </outputLayer1>
<commentLayer> A same as B allowed </commentLayer>
<inputLong> trimTopIndex, trimBottomIndex, trimLeftIndex, trimRightIndex </inputLong>
<inputDouble> fillRedLevel, fillGreenLevel, fillBlueLevel </inputDouble>
<outputLong></outputLong>
<outputDouble></outputDouble>
<comment>  </comment>
</Image1in>
</family>

这是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>
<h2>Routines</h2>
<table border="2">
<tr bgcolor="#7f7f7f">
<td style="text-align:left">Title</td>
<td style="text-align:left">Symbol</td>
<td style="text-align:left">Operation</td>
<td style="text-align:left">Input Layer 1</td>
</tr>
<xsl:for-each select="family/Image1In">
<xsl:sort select="routine"/>
<tr>
<td><xsl:value-of select="routine"/></td>
<td><xsl:value-of select="symbolic"/></td>
<td><xsl:value-of select="operation"/></td>
<td><xsl:value-of select="inputLayer1"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

我很感激有人能提供任何帮助。花了整个周末的时间试图修复。当做RONC-

浏览器不是测试XSLT的好环境。碰巧的是,您的XSLT在使用时出现了一个错误

<xsl:for-each select="family/Image1In">

而不是:

<xsl:for-each select="family/Image1in">

XML区分大小写,您的表达式不选择任何内容。

但是,您应该仍然可以看到表的标题行。相反,您看到的XML的原始文本表明您的浏览器正在应用"同源"安全规则并阻止对样式表的请求。

您可以尝试此代码<xsl:for-each select="family/Image1in">而不是<xsl:for-each select="family/Image1In">或者如果您想删除前导空格和尾部空格,请使用normalize-space()

<?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>
<h2>Routines</h2>
<table border="2">
<tr bgcolor="#7f7f7f">
<td style="text-align:left">Title</td>
<td style="text-align:left">Symbol</td>
<td style="text-align:left">Operation</td>
<td style="text-align:left">Input Layer 1</td>
</tr>
<xsl:for-each select="family/Image1in">
<xsl:sort select="routine"/>
<tr>
<td><xsl:value-of select="normalize-space(routine)"/></td>
<td><xsl:value-of select="normalize-space(symbolic)"/></td>
<td><xsl:value-of select="normalize-space(operation)"/></td>
<td><xsl:value-of select="normalize-space(inputLayer1)"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

演示:https://xsltfiddle.liberty-development.net/3NSSEv5

相关内容

最新更新