【发布时间】:2013-09-03 06:12:43
【问题描述】:
我有以下 XML 文档,需要使用 XSLT 将其解析为 HTML。
<root>
<c>
<c1>
<id>1</id>
<text>US</text>
</c1>
<c1>
<id>2</id>
<text>UK</text>
</c1>
</c>
</root>
下面给出了将其转换为 HTML 的 XSLT。
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="root">
<html>
<xsl:for-each select="c/c1">
**<xsl:variable name="vTemplate" select="text"/>
<xsl:apply-templates select="$vTemplate[@name='text'"/>**
</xsl:for-each>
</html>
</xsl:template>
<xsl:template match="xsl:template[@name='text']" name="text">
<select>
<xsl:attribute name="id">
<xsl:value-of select="id"/>
</xsl:attribute>
</select>
</xsl:template>
</xsl:stylesheet>
我需要调用一个模板取决于文本字段。因此,对于值 US,将执行一个模板,对于 UK,将执行另一个模板。 如何在调用模板时使用变量作为模板名称来实现这一点?我刚试了一下,但它给出了错误。谁能帮我弄清楚我哪里做错了?
【问题讨论】: