使用 XSLT 选择 XML 个节点

Selecting XML nodes with XSLT

我有以下 XML 结构:

        <Car>
            <BMW>
                <Price>100</Price>
            </BMW>
        </Car>
        <Car>
            <TOYOTA>
                <Price>100</Price>
            </TOYOTA>
        </Car>  

我想将其转换成这样的文本:

    <xsl:if test="Car/BMW">
        <xsl:value-of select="Car/BMW/Price" />§BMW§<xsl:value-of select="'&#x000a;'"/>
    </xsl:if>
    <xsl:if test="Car/TOYOTA">
        <xsl:value-of select="Car/TOYOTA/Price" />§TOYOTA§<xsl:value-of select="'&#x000a;'"/>
    </xsl:if>   

问题是我是否可以在没有 if 条件的情况下做同样的事情。

看起来您想要的是每个 Price 元素一行,文本的第二位取自该元素父元素的名称:

<xsl:for-each select="Car/*/Price">
  <xsl:value-of select="concat(., '§', local-name(..), '§&#xa;')/>
</xsl:for-each>