Fabio Barcelona
Fabio Barcelona

Reputation: 63

XSL for-each only showing first tag

I have the following XML Code:

<pregunta tipo="bool" id="A03" tema="2">
    <enunciado>¿Distingue el lenguaje HTML mayúsculas/minúsculas?</enunciado>
    <respuesta>1- Sí</respuesta>
    <respuesta>2- No</respuesta>        
</pregunta>

And this XSL Code:

<body>
    <xsl:for-each select="pregunta">
        <xsl:value-of select="enunciado" />
        <xsl:value-of select="respuesta" />
    </xsl:for-each>
</body>

I want to print the "enunciado" tag and all of the "respuesta" tags for each "pregunta" tag, but it just shows the first "respuesta" tag. How could I fix this?

Upvotes: 2

Views: 40

Answers (1)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

You should iterate over respuesta in some way, e.g. using xsl:for-each:

<body>
    <xsl:for-each select="pregunta">
        <xsl:value-of select="enunciado" />
        <xsl:for-each select="respuesta">
            <xsl:value-of select="." />
        </xsl:for-each>
    </xsl:for-each>
</body>

Upvotes: 1

Related Questions