XSLT Ejemplos
-
-
Nombre:
|
Ejemplo2 |
Ejemplo:
|
<xsl:template match='message'>
<h1><xsl:apply-templates select='//*' mode='big'/></h1>
</xsl:template>
|
-
Nombre:
|
Ejemplo3 |
Ejemplo:
|
<table>
<xsl:attribute name='width'>100%</xsl:attribute>
</table>
|
Comentario:
|
Crea un atributo width para el elemento tabla.
|
-
-
Nombre:
|
Ejemplo5 |
Ejemplo:
|
<xsl:template match='ol'>
<xsl:call-template name='orderedlist'/>
</xsl:template>
|
-
Nombre:
|
Ejemplo6 |
Ejemplo:
|
|
-
Nombre:
|
Ejemplo7 |
Ejemplo:
|
Cargar una variable con bucle
Cargar una variable con otras variables y cadenas
<xsl:variable name='vBdName' select='//BdName '/>
<xsl:variable name='vtable' select='//maintable '/>
<xsl:variable name='vBDatos' select='concat('DataBase: ', $vBdName, '; tabla: ', $vtable) '/>
<xsl:variable name='myString'>
zz<xsl:value-of select='$vBDatos'/>xx
<xsl:for-each select='//DBTCampos/*'>
aa<xsl:value-of select='name(current())'/>:<xsl:value-of select='current()'/>,bb
</xsl:for-each>
</xsl:variable>
El bucle no tiene efecto en el resultado
|
-
Nombre:
|
Ejemplo8 |
Ejemplo:
|
Cargar una variable con choose
<xsl:variable name='color'>
<xsl:choose>
<xsl:when test='@color'>
<xsl:value-of select='@color'/>
</xsl:when>
<xsl:otherwise>red</xsl:otherwise>
</xsl:choose>
</xsl:variable>
|
-
-
-
Nombre:
|
Ejemplo11 |
Ejemplo:
|
<?xml version='1.0'?>
<message>
<to textfrmt='i'>Tove</to>
<from textfrmt='b'>Jani</from>
<text textfrmt='u'>Hello</text>
</message>
El XSL:
<xsl:template match='/'>
<xsl:for-each select='message'>
<xsl:element name='{@textfrmt}'>
<xsl:value-of select='.'/><br />
</xsl:element>
</xsl:for-each>
</xsl:template>
|
-
-
Nombre:
|
Ejemplo13 |
Ejemplo:
|
<xsl:template match='/'>
<table>
<xsl:for-each select='CATALOG/CD'>
<tr>
<td><xsl:value-of select='TITLE'/></td>
<td><xsl:value-of select='ARTIST'/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
|
-
Nombre:
|
Ejemplo14 |
Ejemplo:
|
<xsl:template match='/'>
<xsl:for-each select='CATALOG/CD'>
<xsl:if test='ARTIST='Bob Dylan'>
<xsl:value-of select='TITLE'/><br />
<xsl:value-of select='ARTIST'/>
</xsl:if>
</xsl:for-each>
</xsl:template>
|
-
-
Nombre:
|
Ejemplo16 |
Ejemplo:
|
template que reemplaza una subcadena en una cadena
stringIn: cadena original
substringIn: cadena a reemplazar
substringOut: cadena resultante
Se define:
example showing replacement of '%20' with a single space
<xsl:variable name='myString' select='This%20is%20a%20Test'/>
<xsl:variable name='myString' select='DataBase: NavegacionPub,
table: Media,
Fields: IDPK: NA, NOReg: NodoOrden, Cla1: NodoCla, Cla2: NodoCla, Cla3: NodoCla,
Nombre: NodoTerNombre, Url: NodoTerEnlace, Descripcion: AtribValor, '/>
Se invoca:
<xsl:variable name='myNewString'>
<xsl:call-template name='SubstringReplace'>
<xsl:with-param name='stringIn' select='$myString'/>
<xsl:with-param name='substringIn' select='
'/>
<xsl:with-param name='substringOut' select=' '/>
</xsl:call-template>
</xsl:variable>
Se pone el resultado:
<xsl:value-of select='myNewString'/>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-->
<xsl:template name='SubstringReplace'>
<xsl:param name='stringIn'/>
<xsl:param name='substringIn'/>
<xsl:param name='substringOut'/>
<xsl:choose>
<xsl:when test='contains($stringIn,$substringIn)'>
<xsl:value-of select='concat(substring-before($stringIn,$substringIn),$substringOut)'/>
<xsl:call-template name='SubstringReplace'>
<xsl:with-param name='stringIn' select='substring-after($stringIn,$substringIn)'/>
<xsl:with-param name='substringIn' select='$substringIn'/>
<xsl:with-param name='substringOut' select='$substringOut'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$stringIn'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Nombre:
|
Ejemplo33 |
Ejemplo:
|
<xsl:variable name='car' select='Audi'>
|
-
-
Página generada automáticamente desde la Base de Datos: XSLT/XSLTEjemplos el 28/3/2008 15:49:05