我有一个这样的 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>
我喜欢这样的消息(稍后将它们转换为标签)输出:
A AAA 本田 A BBB 本田 C CCC 丰田
这是我的 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:for-each select="Cell[@colname='2']//MyValue">
<xsl:message>
<xsl:value-of select="Cell[@colname='1']/Value"/>
<xsl:value-of select="."/>
<xsl:value-of select="Cell[@colname='3']/MyCar"/>
</xsl:message>
</xsl:for-each>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
不幸的是,它没有输出我想做的事情:(。
我意识到 for-each 会改变上下文,所以剩余的 value-ofs 不会做任何事情。
对此有什么解决方案?
TIA,
约翰