Foros del Web » Programación para mayores de 30 ;) » Programación General »

Solución: como convertir saltos del linea no indicados en <br>?

Estas en el tema de Solución: como convertir saltos del linea no indicados en <br>? en el foro de Programación General en Foros del Web. Hola quisiera saber si es posible convertir un documento que no tiene marcado los br como por ejemplo <xml> <prueba> Por ejemplo Este texto en ...
  #1 (permalink)  
Antiguo 22/02/2005, 16:26
 
Fecha de Ingreso: febrero-2005
Mensajes: 15
Antigüedad: 19 años, 2 meses
Puntos: 0
Mensaje Solución: como convertir saltos del linea no indicados en <br>?

Hola quisiera saber si es posible convertir un documento que no tiene marcado los br como por ejemplo
<xml>
<prueba>
Por ejemplo
Este texto en 2 reglones HTML
</prueba>

Para que en el navegador me lo muestre como cada linea independiente ... muchas gracias!!

SOLUCION: (usando GTraductor consegui las Keywords de "saltos de línea en XML")
Esta pagina contiene info relativa al HTML pero el ejemplo no esta completo
Aca hay un FAQ IMPRESIONANTE!!! http://www.dpawson.co.uk/xsl/sect2/N7240.html
y aca el codigo [Nota: Me falta lograr añadirle los Tags html arriba y abajo por ejmplo <html></html> si alguien sabe como postee, gracias!]
Código:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="2.0">
<xsl:output method="html" version="1.0" encoding="ISO-8859-1" indent="yes" omit-xml-declaration="yes"/>

   <xsl:template match="texto//text()">
      <xsl:call-template name="make-verbatim">
       <xsl:with-param name="text" select="."/>
     </xsl:call-template>
   </xsl:template>
   
   <xsl:template name="make-verbatim">
     <xsl:param name="text" select="''"/>
   
     <xsl:variable name="starts-with-space"
                   select="substring($text, 1, 1) = ' '"/>
   
     <xsl:variable name="starts-with-nl"
                   select="substring($text, 1, 1) = '&#xA;'"/>
   
     <xsl:variable name="before-space">
       <xsl:if test="contains($text, ' ')">
         <xsl:value-of select="substring-before($text, ' ')"/>
       </xsl:if>
     </xsl:variable>
   
     <xsl:variable name="before-nl">
       <xsl:if test="contains($text, '&#xA;')">
         <xsl:value-of 
	  select="substring-before($text, '&#xA;')"/>
       </xsl:if>
     </xsl:variable>
   
     <xsl:choose>
       <xsl:when test="$starts-with-space">
         <xsl:text>*</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text" 
	  select="substring($text,2)"/>
         </xsl:call-template>
       </xsl:when>
   
       <xsl:when test="$starts-with-nl">
         <br/><xsl:text>&#xA;</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text" 
	  select="substring($text,2)"/>
         </xsl:call-template>
       </xsl:when>
   
       <!-- if the string before a space 
	  is shorter than the string before
            a newline, fix the space...-->
       <xsl:when test="$before-space != ''
                       and ((string-length($before-space)
                             &lt; string-length($before-nl))
                             or $before-nl = '')">
         <xsl:value-of select="$before-space"/>
         <xsl:text>*</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text"
	  select="substring-after($text, ' ')"/>
         </xsl:call-template>
       </xsl:when>
   
       <!-- if the string before a newline 
	  is shorter than the string before
            a space, fix the newline...-->
       <xsl:when test="$before-nl != ''
                       and ((string-length($before-nl)
                             &lt; string-length($before-space))
                             or $before-space = '')">
         <xsl:value-of select="$before-nl"/>
         <br/><xsl:text>&#xA;</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text" 
	  select="substring-after($text, '&#xA;')"/>
         </xsl:call-template>
       </xsl:when>
   
       <!-- the string before the newline and the string before the
            space are the same; which means they must both be empty -->
       <xsl:otherwise>
         <xsl:value-of select="$text"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
</xsl:stylesheet>

Última edición por deZtino; 23/02/2005 a las 10:46 Razón: Encontre la solucion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:28.