I need some help with an issue I can’t figure out.
I have the following xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="prueba.xsl"?>
<ficha>
<titulo></titulo>
<bloque>
<texto></texto>
<pregunta id="1" tipo="checkSN">
<texto>Acredita curso bienestar animal minimo 20 h</texto>
</pregunta>
<pregunta id="2" tipo="texto">
<texto>Sistemática inspección</texto>
</pregunta>
<grupo>
<texto>trato adecuado enfermos</texto>
<pregunta id="3" tipo="desplegableSNP">
<texto>Recetas correspondientes</texto>
</pregunta>
<pregunta id="4" tipo="multiple">
<texto>Disponen de comida y bebida</texto>
</pregunta>
</grupo>
<grupo>
<texto>
Heridos/Enfermos
</texto>
<pregunta id="5" tipo="multiple">
<texto>Se aprecian heridos o enfermos momento inspeccion</texto>
</pregunta>
<pregunta id="6" tipo="multiple">
<texto>Separados del resto</texto>
</pregunta>
<pregunta id="7" tipo="multiple">
<texto>Disponen de comida y bebida</texto>
</pregunta>
<pregunta id="8" tipo="multiple">
<texto>Disponen de comida y bebida</texto>
</pregunta>
</grupo>
</bloque>
<bloque>
<texto>Condiciones específicas de alojamiento y manejo</texto>
</bloque>
</ficha>
And The folliwng XSL sheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="prueba.css" />
</head>
<body>
<h2><xsl:value-of select="/ficha/titulo"/></h2>
<h3>1: <xsl:value-of select="//pregunta[1]/@id"/></h3>
<h3>2: <xsl:value-of select="//pregunta[2]/@id"/></h3>
<h3>3: <xsl:value-of select="//pregunta[3]/@id"/></h3>
<h3>4: <xsl:value-of select="//pregunta[4]/@id"/></h3>
<h3>5: <xsl:value-of select="//pregunta[5]/@id"/></h3>
<h3>6: <xsl:value-of select="//pregunta[6]/@id"/></h3>
<h3>7: <xsl:value-of select="//pregunta[7]/@id"/></h3>
<h3>8: <xsl:value-of select="//pregunta[8]/@id"/></h3>
<h3>c: <xsl:value-of select="count(//pregunta)"/></h3>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When I load them I got this result:
1: 1
2: 2
3: 7
4: 8
5:
6:
7:
8:
c: 8
I don’t understand why it’s ignoring some nodes . If I include new nodes or move them, it always shows 4 results, from node at position 5 to 8 it never shows anything. I need to use this type of selecting because it’s from a Java application, the stylesheet is just for testing.
Put
//preguntain parenthesis. Change your XPath expressions to(//pregunta)[1]/@id,(//pregunta)[2]/@id…Without parenthesis e.g.
//pregunta[4]evaluates to allpreguntaelements which are at the fourth position of their parent element.However (//pregunta)[4] first calculates the sequence of all
preguntaelements and then takes the fourth element of that sequence.