简体   繁体   中英

for-each loop in XSLT

Please excuse me, I'm no expert in XSLT (AT ALL) so this could be really really bad but...

I have my xml (for example)

<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)

    <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
and bar1 bar1

Sequence:2
and bar2 bar2

Sequence:3
and bar3 bar3

But I'm getting ...

Sequence:1
and

Sequence:2
and

Sequence:3
and

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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