Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/08/2004, 04:43
Avatar de Helbira
Helbira
 
Fecha de Ingreso: octubre-2001
Ubicación: Sevilla, España
Mensajes: 1.228
Antigüedad: 22 años, 6 meses
Puntos: 5
Reconozco que me ha costado

A ver si te vale esta solución

prueba.xml
Código:
<?xml version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet type="text/xsl" href="prueba.xsl"?> 
<raiz> 
   <datos>
	 <juan>
	   <personal estadocivil="soltero">
		 JUAN		 
	   </personal>
	 </juan>
   </datos> 
</raiz>

prueba.xsl
Código:
 
<?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="/">
	<xsl:variable name="ruta">/raiz/datos/juan</xsl:variable>
	<xsl:variable name="campo">/personal</xsl:variable>
	<xsl:variable name="ultimo">
	  <xsl:call-template name="getLast">
		<xsl:with-param name="ruta">
		  <xsl:value-of select="concat($ruta,$campo)" />
		</xsl:with-param>
	  </xsl:call-template>
	</xsl:variable>
	<xsl:value-of select="//*[name()=$ultimo]" />
  </xsl:template>
<xsl:template name="getLast">
  <!-- Recorremos la ruta y nos quedamos con el nombre 
	-+ de la etiqueta más profunda en la ruta indicada -->
  <xsl:param name="ruta" />
  <xsl:param name="pattern" select="'/'" />
 <xsl:choose>
   <xsl:when test="contains($ruta, $pattern)">
	  <xsl:variable name="ultimo">
		<xsl:value-of select="substring-after($ruta,$pattern)" />
	  </xsl:variable>
	  <xsl:choose>
		<xsl:when test="not(contains($ultimo,$pattern)) and $ultimo!=''">
		  <xsl:value-of select="$ultimo" />
		</xsl:when>
		<xsl:otherwise>
		  <xsl:call-template name="getLast">
		 <xsl:with-param name="ruta" select="substring-after($ruta, $pattern)" />
		</xsl:call-template>
	  </xsl:otherwise>
	  </xsl:choose>
   </xsl:when>
   <xsl:otherwise>
	  <xsl:value-of select="$ruta" />
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>
</xsl:stylesheet>
Aviso! El caso en que quieras consultar el valor de un atributo no lo contempla. Completalo tú para que trate también el caso de vlores de atributos.
Tendrías que tocar el template "getLast".

Suerte!