instruccion blanca en xml

19/01/2004 - 12:42 por mani14 | Informe spam
buenas a tod@s:
Tengo un problema con una instruccion en xml, es lo siguiente.
Estoy intentando transformar un fichero en xml a xul(otro
formato xml). Parece que me transforma bien, menos un
pequeño problema, la ultima instruccion en el xsl es
<xsl:template match="node()|@*"> <!-- -->

</xsl:template>

Que si no he entendido mal, lo que hace es, para cualquier
otro nodo que no sea los que he dicho antes que este, NO
HACER NADA. El problema me da en qeu , bien, no hace nada,
pero a la hora deescribirme el texto en el nuevo fichero,
me lo hace sin salto de linea ni nada, por lo que ver los
fallos que me ha generado es muy complicado. Sabe alguien
cual puede ser el problema?
Si no entendieron algo pregunten y se lo volvere a explicar
de otra forma, hay veces que no me explico excesivamente
bien ;)
Muchisimas gracias a tod@s.
Saludos.
Mani14
 

Leer las respuestas

#1 mani14
22/01/2004 - 11:28 | Informe spam
vale, no os lo habia puesto pq me parecia escesibamente
largo. ahi va primero el xsl
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/ga...">
<!-- voy cogiendo las variables de la ventana, para
ponerselo como atributo -->
<xsl:output method="xml" version="1.0"
encoding="ISO-8859-15"/>
<xsl:template match="/window">
<xsl:variable name="wid">
<xsl:value-of select="id"/>
</xsl:variable>
<xsl:variable name="wtitle">
<xsl:value-of select="title"/>
</xsl:variable>
<xsl:variable name="worient">
<xsl:value-of select="orient"/>
</xsl:variable>
<xsl:variable name="wonload">
<xsl:value-of select="onload"/>
</xsl:variable>
<window id="{$wid}" title="{$wtitle}" orient="{$worient}"
onload="{$wonload}" >
<!--<script> <xsl:value-of select="script"/> </script>-->
<xsl:for-each select="node()">

<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</window>
</xsl:template>


<!--Comenzamos a machear lo que nos encontramos en box que
seran una serie de atributos, y una ristra de botones -->
<xsl:template match="script">
<script>
<xsl:value-of select="."/>
</script>
</xsl:template>


<xsl:template match="box">
<xsl:variable name="id">
<xsl:value-of select="id"/>
</xsl:variable>
<xsl:variable name="orient">
<xsl:value-of select="orient"/>
</xsl:variable>
<xsl:variable name="flex">
<xsl:value-of select="flex"/>
</xsl:variable>
<xsl:variable name="align">
<xsl:value-of select="align"/>
</xsl:variable>
<xsl:variable name="style">
<xsl:value-of select="style"/>
</xsl:variable>
<!--Empezamos a poner las etiquetas de box, con las
variables encontradas, y recorremos los nodos para
encontrar los botones. -->
<box id="{$id}" orient="{$orient}" flex="{$flex}"
aling="{$align}" style="{$style}" >
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</box>
</xsl:template>
<!--se acaba con el box-->

<!--Comenzamos con el mas compliado de todos, el groupbox,
por su gran ramificacion-->
<xsl:template match="groupbox">
<groupbox>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</groupbox>

</xsl:template>
<!--se acaba con el groupbox-->

<!--comenzamos con caption, qeu esta dentro de groupbox.-->
<xsl:template match="caption">
<caption>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</caption>
</xsl:template>
<!--se acaba con el cption-->

<!-- comenzamos con el label, que tb estara dentro de
caption-->
<xsl:template match="labeli">
<xsl:variable name="for">
<xsl:value-of select="for"/>
</xsl:variable>
<xsl:variable name="value">
<xsl:value-of select="value"/>
</xsl:variable>
<label for="{$for}" value="{$value}" />
</xsl:template>
<!--se acaba con el label-->

<!-- comenzamos con elmenulist dentro de caption-->
<xsl:template match="menulist">
<xsl:variable name="id">
<xsl:value-of select="id"/>
</xsl:variable>
<xsl:variable name="label">
<xsl:value-of select="label"/>
</xsl:variable>
<xsl:variable name="oncommand">
<xsl:value-of select="oncommand"/>
</xsl:variable>

<menulist id="{$id}" label="{$label}"
oncommand="{$oncommand}">
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>

</menulist>

</xsl:template>
<!--se acaba con el menulist-->

<!--comenzamos con menupopup-->
<xsl:template match="menupopup">
<menupopup>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</menupopup>
</xsl:template>
<!--se acaba con el menupopup-->


<!--comenzamos con caption, qeu esta dentro de menuitem.-->
<xsl:template match="menuitem">
<xsl:variable name="value">
<xsl:value-of select="value"/>
</xsl:variable>
<xsl:variable name="label">
<xsl:value-of select="label"/>
</xsl:variable>
<xsl:variable name="selected">
<xsl:value-of select="selected"/>
</xsl:variable>
<menuitem value="{$value}" label="{$label}"
selected="{$selected}" />

</xsl:template>
<!--se acaba con el menuitem-->

<!--comenzamos con columns. sera igual rows, solo hay que
abrir, leer y cerrar.-->
<xsl:template match="columns">
<columns>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</columns>
</xsl:template>
<!--se acaba con el columns-->

<!--se tendra ahora que leer las diferentes columnas.-->
<xsl:template match="column">
<xsl:variable name="flex">
<xsl:value-of select="flex"/>
</xsl:variable>
<column flex="{$flex}" />
</xsl:template>
<!--se acaba con el column-->


<!--Lo mismo de antes pero ahora con rows-->
<xsl:template match="rows">
<rows>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</rows>
</xsl:template>
<!--se acaba con el rows-->

<!--se tendra ahora que leer las diferentes rows, que a su
vez tendran lasbel y mas cosas..-->
<xsl:template match="row">
<row>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</row>
</xsl:template>
<!--se acaba con el column-->






<!--Macheamos el boton -->

<xsl:template match="button">
<xsl:variable name="bid">
<xsl:value-of select="id"/>
</xsl:variable>
<xsl:variable name="blabel">
<xsl:value-of select="label"/>
</xsl:variable>

<button id="{$bid}" label="{$blabel}" />
</xsl:template>
<!--Acabamos con el boton -->

<!--Macheamos el grid -->

<xsl:template match="grid">
<grid>
<xsl:for-each select="node()">
<!--nos dice que recorramos todos los nodos -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</grid>
</xsl:template>
<!--Acabamos con el boton -->



<!--Macheamos el textbox, ultimo elemento a mirar -->


<xsl:template match="textbox">
<xsl:variable name="id">
<xsl:value-of select="id"/>
</xsl:variable>
<xsl:variable name="value">
<xsl:value-of select="value"/>
</xsl:variable>
<xsl:variable name="onchange">
<xsl:value-of select="onchange"/>
</xsl:variable>
<textbox id="{$id}" value="{$value}"
onchange="{$onchange}" />
</xsl:template>
<!--Acabamos con el textbox -->

<!-- <xsl:template match="node()|@*">
<xsl:apply-templates select="node()|@*"/>

</xsl:template> -->

</xsl:stylesheet>



y ahora os pongo el xml


<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 2 U
(http://www.xmlspy.com) by felix (fvs) -->
<!--felix (fvs) -->
<?xml-stylesheet type="text/xsl" href="./prueba4_1.xsl"?>
<window xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<id>aligner-window</id>
<title>Box Alignment Example</title>
<orient>horizontal</orient>
<onload>init();</onload>

<!-- xsi:noNamespaceSchemaLocation="C:\Documents and
Settings\mani14f\Escritorio\pfc\pfcxml\prueba4_1.xsd" -->
<script>

<!-- <![CDATA[ -->

var theItem;

function init()
{
changeEditingItem("thebox");
}

function changeEditingItem(elemid)
{
theItem=document.getElementById(elemid);

document.getElementById("flexval").value=theItem.getAttribute("flex");

document.getElementById("flexgroupval").value=theItem.getAttribute("flexgroup");

document.getElementById("ordinalval").value=theItem.getAttribute("ordinal");


setMenuItemSelection("alignval",theItem.getAttribute("align"));
setMenuItemSelection("packval",theItem.getAttribute("pack"));

setMenuItemSelection("orientval",theItem.getAttribute("orient"));
setMenuItemSelection("dirval",theItem.getAttribute("dir"));

var styl=theItem.getAttribute("style");

setStyleValue(styl,"width","widthval");
setStyleValue(styl,"min-width","minwidthval");
setStyleValue(styl,"max-width","maxwidthval");
setStyleValue(styl,"height","heightval");
setStyleValue(styl,"min-height","minheightval");
setStyleValue(styl,"max-height","maxheightval");
}

function setMenuItemSelection(menuid,val)
{
var menu=document.getElementById(menuid);
var items=menu.firstChild.childNodes;
for (var t=0;t&lt;items.length;t++){
if (items[t].value==val){
menu.selectedItem=items[t];
return;
}
}
menu.selectedItem=items[0];
}

function setStyleValue(styl,prop,elemid)
{
var val;
var len=prop.length+2;
var idx=styl.indexOf(" "+prop+":");
if (idx==-1) val="";
else val=styl.substring(idx+len,styl.indexOf("px",idx+len));
document.getElementById(elemid).value=val;
}

function changeItem(event,attr)
{
if (event.target.value=="" || event.target.value==""){
theItem.removeAttribute(attr);
}
else {
theItem.setAttribute(attr,event.target.value);
}
}

function changeStyle(event,attr)
{
var styl=theItem.getAttribute("style");
if (styl.indexOf(" "+attr)>=0){
var stylexp=new RegExp(" "+attr+":\s*[0-9]*px;");
if (event.target.value=="") styl=styl.replace(stylexp,"");
else styl=styl.replace(stylexp,"
"+attr+":"+event.target.value+"px;");
theItem.setAttribute("style", styl);
}
else {
theItem.setAttribute("style", " "+styl+"
"+attr+":"+event.target.value+"px;");
}
}

<!-- ]]> -->

</script>

<box>
<id>thebox</id>
<orient>horizontal</orient>
<flex>1</flex>
<align>start</align>
<style> border: 1px solid black; margin: 1em; padding:
1em;</style>
<button>
<id>b1</id>
<label>Cat</label>
</button>
<button>
<id>b2</id>
<label>Parrot</label>
</button>
<button>
<id>b3</id>
<label>Porcupine</label>
</button>
</box>
<groupbox>
<caption>
<labeli>
<for>edititem</for>
<value>Edit:</value>
</labeli>
<menulist>
<id>edititem</id>
<label>Box</label>

<oncommand>changeEditingItem(event.target.value);</oncommand>
<menupopup>
<menuitem>
<value>thebox</value>
<label>Box</label>
<selected>true</selected>
</menuitem>
<menuitem>
<value>b1</value>
<label>Cat</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>b2</value>
<label>Parrot</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>b3</value>
<label>Porcupine</label>
<selected>false</selected>
</menuitem>
</menupopup>
</menulist>
</caption>
<grid>
<columns>
<column>
<flex>1</flex>
</column>
</columns>
<rows>
<row>
<labeli>
<for>flexval</for>
<value>flex:</value>
</labeli>
<textbox>
<id>flexval</id>
<value>1</value>
<onchange>changeItem(event,'flex');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>flexgroupval</for>
<value>flexgroup:</value>
</labeli>
<textbox>
<id>flexgroupval</id>
<onchange>changeItem(event,'flexgroup');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>alignval</for>
<value>align:</value>
</labeli>
<menulist>
<id>alignval</id>
<label>Stretch</label>
<oncommand>changeItem(event,'align');</oncommand>
<menupopup>
<menuitem>
<value></value>
<label>(None)</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>start</value>
<label>Start</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>center</value>
<label>Center</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>end</value>
<label>End</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>baseline</value>
<label>Baseline</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>stretch</value>
<label>Stretch</label>
<selected>true</selected>
</menuitem>
</menupopup>
</menulist>
</row>
<row>
<labeli>
<for>packval</for>
<value>pack:</value>
</labeli>
<menulist>
<id>packval</id>
<label>packval</label>
<oncommand>changeItem(event,'pack');</oncommand>
<menupopup>
<menuitem>
<value></value>
<label>(None)</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>start</value>
<label>Start</label>
<selected>true</selected>
</menuitem>
<menuitem>
<value>center</value>
<label>Center</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>end</value>
<label>End</label>
<selected>false</selected>
</menuitem>
</menupopup>
</menulist>
</row>
<row>
<labeli>
<for>orientval</for>
<value>orient:</value>
</labeli>
<menulist>
<id>orientval</id>
<label>Horizontal</label>
<oncommand>changeItem(event,'orient');</oncommand>
<menupopup>
<menuitem>
<value></value>
<label>(None)</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>horizontal</value>
<label>Horizontal</label>
<selected>true</selected>
</menuitem>
<menuitem>
<value>vertical</value>
<label>Vertical</label>
<selected>false</selected>
</menuitem>
</menupopup>
</menulist>
</row>
<row>
<labeli>
<for>dirval</for>
<value>dir:</value>
</labeli>
<menulist>
<id>dirval</id>
<label>Dir</label>
<oncommand>changeItem(event,'dir');</oncommand>
<menupopup>
<menuitem>
<value></value>
<label>(None)</label>
<selected>false</selected>
</menuitem>
<menuitem>
<value>ltr</value>
<label>ltr</label>
<selected>true</selected>
</menuitem>
<menuitem>
<value>rtl</value>
<label>rtl</label>
<selected>false</selected>
</menuitem>
</menupopup>
</menulist>
</row>
<row>
<labeli>
<for>ordinalval</for>
<value>ordinal:</value>
</labeli>
<textbox>
<id>ordinalval</id>
<value>0</value>
<onchange>changeItem(event,'ordinal');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>widthval</for>
<value>width:</value>
</labeli>
<textbox>
<id>widthval</id>
<value>0</value>
<onchange>changeStyle(event,'width');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>minwidthval</for>
<value>minwidth:</value>
</labeli>
<textbox>
<id>minwidthval</id>
<value>0</value>
<onchange>changeStyle(event,'min-width');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>maxwidthval</for>
<value>maxwidth:</value>
</labeli>
<textbox>
<id>maxwidthval</id>
<value>0</value>
<onchange>changeStyle(event,'max-width');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>heightval</for>
<value>height:</value>
</labeli>
<textbox>
<id>heightval</id>
<value>0</value>
<onchange>changeStyle(event,'height');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>minheightval</for>
<value>minheight:</value>
</labeli>
<textbox>
<id>minheightval</id>
<value>0</value>
<onchange>changeStyle(event,'min-height');</onchange>
</textbox>
</row>
<row>
<labeli>
<for>maxheightval</for>
<value>maxheight:</value>
</labeli>
<textbox>
<id>maxheightval</id>
<value>0</value>
<onchange>changeStyle(event,'max-height');</onchange>
</textbox>
</row>
</rows>
</grid>
</groupbox>
</window>




Espero que os aclareis, para cualquier duda me comentais.
como lo he puesto, comentando lo ultimo en el xsl me sale
dos veces los atributos(eso me pasa por utilizar
variables), pero si no los comento, me sale de una forma un
tanto extraña, la conversion, ya que no pega saltos de
linea. buena ya lo vereis.
Saludos.

Preguntas similares