<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Indalcasa &#187; Xml</title>
	<atom:link href="http://www.indalcasa.com/category/programacion/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indalcasa.com</link>
	<description>Un blog de tecnologia</description>
	<lastBuildDate>Thu, 02 Sep 2010 00:34:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Reemplazar texto en transformada xslt</title>
		<link>http://www.indalcasa.com/programacion/reemplazar-texto-en-transformada-xslt/</link>
		<comments>http://www.indalcasa.com/programacion/reemplazar-texto-en-transformada-xslt/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 17:44:07 +0000</pubDate>
		<dc:creator>Juan</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[Xml]]></category>
		<category><![CDATA[Xslt]]></category>
		<category><![CDATA[transformada]]></category>
		<category><![CDATA[transformadas]]></category>
		<category><![CDATA[xsl]]></category>

		<guid isPermaLink="false">http://www.indalcasa.com/?p=207</guid>
		<description><![CDATA[Trabajo desde hace años usando de una forma intensiva las transformadas xslt, y a pesar de que son fáciles de utilizar y se pueden hacer infinidad de cosas, llegando al caso de ser propiamente dicho, un lenguaje de programación, hay algo que siempre he echado en falta. A pesar de que xsl tiene funciones para [...]]]></description>
			<content:encoded><![CDATA[<p>Trabajo desde hace años usando de una forma intensiva las <strong>transformadas xslt</strong>, y a pesar de que son fáciles de utilizar y se pueden hacer infinidad de cosas, llegando al caso de ser propiamente dicho, un lenguaje de programación, hay algo que siempre he echado en falta. A pesar de que <strong>xsl</strong> tiene funciones para el tratamiento de cadenas como <strong>substring</strong>, <strong>startwith</strong>, <strong>concat</strong>, etc. nunca he visto que tenga una <strong>función para reemplazar texto</strong>, algo que seria muy útil. Siempre que he tenido que hacer un <strong>reemplazo de texto</strong> lo he hecho de diferentes formas, a cual mas chapucera. Si tenia que sustituir una frase entera, llenaba el <strong>xsl</strong> de <strong>xsl:if</strong> o de <strong>xsl:choose</strong> con sus consecuentes <strong>xsl:when</strong>, pero si tenia que sustituir parte de una frase, ya la cosa se complicaba mas, usando casi siempre el nombre de espacio <strong>user</strong>, y definiendo una función en el lenguaje que utilizaba (en mi caso .net), pero esto tiene un problema, si por algún casual, quiero migrar a otro lenguaje (que no veo yo a mi jefe mucho por la labor), la <strong>transformada</strong> no me serviría fuera del entorno de .net.</p>
<p>Para solucionar este problema, decidí crear una <strong>función de xsl</strong>, mas que una función es un <strong>template</strong>, pero como a mi me gusta usar los <strong>templates</strong> como funciones con parámetros, también me gusta llamarlas funciones. Bueno, el caso es que he creado una <strong>función/template</strong>, que recibe 3 parámetros, y que vendría a ser mas o menos como el <strong>replace de php</strong>, pero con el funcionamiento del <strong>replace de javascript</strong>, porque de momento solo reemplaza de 1 en 1, digamos que no es un <strong>replace all</strong>. La función recibe 3 parámetros, uno con el texto a base, la cadena de donde queremos reemplazar el texto, otro parámetro con el texto que va a ser reemplazado, y otro parámetro con el texto a reemplazar. El código de la función seria el siguiente:</p>
<blockquote><pre class="xml"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Funcion replace --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replace&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Cadena de texto --&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Texto que va a ser reemplazado --&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replaceText&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Texto a reemplazar --&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replacedText&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- El replace propiamente dicho --&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-before($text,$replaceText)&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$replacedText&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-after($text,$replaceText)&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsl:template<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Ejemplo de utilizacion --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;price&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:call-template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replace&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$xml/POSIBILIDADES_PRECIO-IDA&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replaceText&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;','&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replacedText&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;'.'&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsl:call-template<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsl:variable<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
</blockquote>
<p>Espero que esta pequeña f<strong>unción para xsl</strong>, os sea tan útil como a mi. Por cierto, el ejemplo me lo saque de uno que monte en el curro, así que cada uno lo tendrá que modificar en base a sus necesidades. A ver si me lo curro un poco y modifico la función para que sea un r<strong>eplace all</strong>, en lugar de un <strong>replace one</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.indalcasa.com/programacion/reemplazar-texto-en-transformada-xslt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Símbolo del euro en xml o xslt sin utf-8</title>
		<link>http://www.indalcasa.com/programacion/html/simbolo-del-euro-en-xml-o-xslt-sin-utf-8/</link>
		<comments>http://www.indalcasa.com/programacion/html/simbolo-del-euro-en-xml-o-xslt-sin-utf-8/#comments</comments>
		<pubDate>Mon, 26 May 2008 18:11:43 +0000</pubDate>
		<dc:creator>Juan</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[Xml]]></category>
		<category><![CDATA[Xslt]]></category>
		<category><![CDATA[euro]]></category>
		<category><![CDATA[iso-8859-1]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[xsl]]></category>

		<guid isPermaLink="false">http://www.indalcasa.com/?p=51</guid>
		<description><![CDATA[Durante el desarrollo de mi último proyecto, me encontré con un xml de transformación o xslt, donde debía de usar el símbolo del euro (€), pero esta transformada, que no deja de ser un xml, estaba codificada en iso-8859-1, y no podía cambiar la codificación. A la hora de añadir el símbolo del euro, si [...]]]></description>
			<content:encoded><![CDATA[<p>Durante el desarrollo de mi último proyecto, me encontré con un <strong>xml </strong>de transformación o <strong>xslt</strong>, donde debía de usar el <strong>símbolo del euro (€)</strong>, pero esta <strong>transformada</strong>, que no deja de ser un <strong>xml</strong>, estaba codificada en <strong>iso-8859-1</strong>, y no podía cambiar la <strong>codificación</strong>. A la hora de añadir el <strong>símbolo del euro</strong>, si usaba directamente el <strong>carácter €</strong>, fallaba porque estaba <strong>mezclando codificaciones</strong>, y si usaba <strong>&amp;euro;</strong> como viene siendo en <strong>html</strong>, fallaba porque no es un <strong>carácter válido de xslt</strong>. La solución, usar los <strong>caracteres especiales</strong>, en este caso para el <strong>euro (€)</strong> es el <strong>&amp;#128;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.indalcasa.com/programacion/html/simbolo-del-euro-en-xml-o-xslt-sin-utf-8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
