C# XSLT-将XML输入转换为具有两列的HTML表
这是我的源XML文件:C# XSLT-将XML输入转换为具有两列的HTML表,c#,xslt,xpath,C#,Xslt,Xpath,这是我的源XML文件: <?xml version="1.0" encoding="utf-8"?> <root> <employees> <region> <country>AUS</country> <count>3</count> </region> <region> <country>BEL&l
<?xml version="1.0" encoding="utf-8"?>
<root>
<employees>
<region>
<country>AUS</country>
<count>3</count>
</region>
<region>
<country>BEL</country>
<count>1</count>
</region>
<region>
<country>PER</country>
<count>1</count>
</region>
<region>
<country>ALA</country>
<count>5</count>
</region>
</employees>
</root>
但它正在回归:
Australia | Alaska
------------------
Peru | Alaska
下面是一个XSLT提琴,演示了这个问题:
我怀疑问题在于将国家代码映射到显示名称,因为如果我不这样做,国家代码将正确显示在输出HTML表中
我在XSLT方面没有太多经验,因此希望您能给我一些指导,告诉我哪里出了问题。我恐怕对此没有很好的解释,但如果您改变:
<xsl:variable name="countryRight" select="following-sibling::region/country"></xsl:variable>
致:
它将按预期工作:为什么这个标签是XSLT 2.0?您的样式表具有
version=“1.0”
,并且您似乎正在使用Microsoft处理器。很抱歉,我已删除此标记。原因是,如果没有[1]
,$countryRight
是一组节点,其中包含该区域的所有以下同级节点,以及“=”因此,比较将返回与其中任何项匹配的所有条目键。在XSLT1.0中,选择这些匹配的条目
元素中的第一个,给定的数据是ALA=Alland孤岛。但不知道阿拉斯加从哪里来!
Australia | Alaska
------------------
Peru | Alaska
<xsl:variable name="countryRight" select="following-sibling::region/country"></xsl:variable>
<xsl:variable name="countryRight" select="following-sibling::region[1]/country"></xsl:variable>