xml - XPATH Selecting by position returns incoherent results -


i need issue can't figure out.

i have 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 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 load them got result:

1: 1 2: 2 3: 7 4: 8 5: 6: 7: 8: c: 8

i don't understand why it's ignoring nodes . if include new nodes or move them, shows 4 results, node @ position 5 8 never shows anything. need use type of selecting because it's java application, stylesheet testing.

put //pregunta in parenthesis. change xpath expressions (//pregunta)[1]/@id, (//pregunta)[2]/@id ...

without parenthesis e.g. //pregunta[4] evaluates pregunta elements @ fourth position of parent element.

however (//pregunta)[4] first calculates sequence of pregunta elements , takes fourth element of sequence.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -