简体   繁体   English

XSLT中的for-each循环

[英]for-each loop in XSLT

Please excuse me, I'm no expert in XSLT (AT ALL) so this could be really really bad but... 请原谅,我不是XSLT(AT ALL)的专家,所以这可能真的很糟糕,但是...

I have my xml (for example) 我有我的xml(例如)

<tests>
    <test seq="1">
        <foo name="foo1" />
        <bar name="bar1" />
    </test>
    <test seq="2">
        <foo name="foo2" />
        <bar name="bar2" />
    </test>
    <test seq="1">
        <foo name="foo3" />
        <bar name="bar3" />
    </test>
<tests>

and I have my xslt (again for example) 而且我有我的xslt(例如,再次)

    <xsl:template match="dptest">
        <xsl:for-each select="/tests/test">
            <p>
                Sequence:<xsl:value-of select="@seq"/><br/>
                <b>Name Of Foo:</b><xsl:value-of select="/foo/@name"/> and <b>Name Of Bar:</b><xsl:value-of select="/bar/@name"/>
            </p>
        </xsl:for-each>
    </xsl:template>

and I'm wanting to spit out... 我想吐...

Sequence:1 顺序:1
Name Of Foo: foo1 and Name Of Bar: bar1 Foo的名称:foo1Bar的名称: bar1

Sequence:2 顺序:2
Name Of Foo: foo2 and Name Of Bar: bar2 Foo的名称:foo2Bar的名称: bar2

Sequence:3 顺序:3
Name Of Foo: foo3 and Name Of Bar: bar3 Foo的名称:foo3Bar的名称: bar3

But I'm getting ... 但是我越来越...

Sequence:1 顺序:1
Name Of Foo: and Name Of Bar: Foo名称:Bar名称:

Sequence:2 顺序:2
Name Of Foo: and Name Of Bar: Foo名称:Bar名称:

Sequence:3 顺序:3
Name Of Foo: and Name Of Bar: Foo名称:Bar名称:

if anyone could point me in the right direction I would appreciate it MASSIVELY :) 如果有人能指出我正确的方向,我将非常感激:)

Cheers 干杯

Daz 达兹

don't use a full path 不要使用完整路径

select="/foo/@name"

but a relative path 但是一条相对的道路

select="foo/@name"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM