我有一个这样的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<Section>
<Chapter>
<Cell colname="1">
<Value>A</Value>
</Cell>
<Cell colname="2">
<MyValue>AAA</MyValue>
<MyValue>BBB</MyValue>
</Cell>
<Cell colname="3">
<MyCar>Honda</MyCar>
</Cell>
</Chapter>
<Chapter>
<Cell colname="1">
<Value>C</Value>
</Cell>
<Cell colname="2">
<MyValue>CCC</MyValue>
</Cell>
<Cell colname="3">
<MyCar>Toyota</MyCar>
</Cell>
</Chapter>
</Section>
我有一个这样的 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="Section/Chapter"/>
</xsl:template>
<xsl:template match="Chapter">
<xsl:apply-templates select="./Cell/MyValue"/>
</xsl:template>
<xsl:template match="MyValue">
<xsl:message>
<xsl:value-of select="../../Cell/@colname"/>
<xsl:value-of select="../../Cell[@colname='1']/Value"/>
<xsl:value-of select="."/>
<xsl:value-of select="../../Cell[@colname='3']/MyCar"/>
</xsl:message>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
问题是调试输出显示为 1 2 3 A AAA Honda 1 2 3 A BBB Honda 1 2 3 C CCC Toyota。我想要 1 A 2 AAA 3 Honda 1 A 2 BBB 3 Honda 1 C 2 CCC 3 Toyota。基本上正确获取属性 colname 的值。
所以几个问题:
- 我做错了什么 ?。
- 有一个序列 1 2 3 生成为什么?
TIA,
约翰