PDA

View Full Version : Trasformare xml via xslt


f0/\/2!3
26-09-2006, 10:33
Il mio problema è questo: ho un file xml che mi restituisce dei valori in un attributo e un altro file xml dove cambiare altri valori di attributi di conseguenza in certi punti. Pensavo ad un passaggio via XSLT ma non so bene come posso usarlo...

Vi posto un pezzettino dei file per cercare di fare chiarezza:

Primo file xml: mi interessa il valore dell'attributo posizione.
[...]
<sezione posizione='1'>
<corsia posizione='1' nAuto='0' nTir='1' >
<veicolo ID='403' vMedia='80.00' currentV='80.00' enter='0' exit='0' type='tir'/>
</corsia>
[...]

Secondo file xml o file di output: a seconda del valore nel file precedente devo cambiare il valore dell'attributo translation.

[...]
<Scene>
<Transform DEF="dad_Import_golf_wrl" translation="16 0 8.69656" rotation="0 1 0 3.142" scale="8.79334 8.79334 8.79334">
[...]


Come fare? :(

f0/\/2!3
26-09-2006, 18:07
Mi spiegate perchè XMLSpy mi dice che la funzione Incrementa non è un XPath valido??? non ne posso piùùùùùùùùùùùùù non è xpath è ovvio che non sia valida ma da quanto ho visto in giro si richiama così!!!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:az="urn:scripts:JScript">
<msxsl:script language="JScript" implements-prefix="az">
var spo=0;
function Incrementa()
{
spo=spo+430;
return spo;
}
</msxsl:script>
<xslutput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="sez" select="count(results/snapshot[@number=1]/sezione)"></xsl:variable>
<xsl:template match="/">
<X3D profile="Immersive" version="3.0">
<Scene>
<xsl:if test="$sez &gt; 0">
<xsl:for-each select="results/snapshot[@number=1]/sezione">
<xsl:apply-templates select="//sezione" />
</xsl:for-each>
</xsl:if>
</Scene>
</X3D>
</xsl:template>
<xsl:template match="sezione">
<Transform DEF="Piano_Stradale">
<xsl:attribute name="translation">0 0 <xsl:value-of select="az:Incrementa()" /></xsl:attribute>
<Viewpoint DEF="GenericoA" description="GenericoA" jump="true" fieldOfView="0.785" position="40 50 -200" orientation="-0 .977 .215 2.994"/>
<Viewpoint DEF="GenericoB" description="GenericoB" jump="true" fieldOfView="0.785" position="40 50 200" orientation="-.804 .588 .085 .443"/>
<Transform DEF="dad_Viste_Laterali" translation="15 0 0" rotation="0 0 1 .524">
<Viewpoint DEF="A1" containerField="children" description="A1" jump="true" fieldOfView="0.785" position="75 0 172" orientation="0 1 0 1.571"/>
<Viewpoint DEF="A2" containerField="children" description="A2" jump="true" fieldOfView="0.785" position="75 0 86" orientation="0 1 0 1.571"/>
<Viewpoint DEF="A3" containerField="children" description="A3" jump="true" fieldOfView="0.785" position="75 0 0" orientation="0 1 0 1.571"/>
<Viewpoint DEF="A4" containerField="children" description="A4" jump="true" fieldOfView="0.785" position="75 0 -86" orientation="0 1 0 1.571"/>
<Viewpoint DEF="A5" containerField="children" description="A5" jump="true" fieldOfView="0.785" position="75 0 -172" orientation="0 1 0 1.571"/>
</Transform>
<Viewpoint DEF="Alto1" description="Alto1" jump="true" fieldOfView="0.785" position="0 200 130" orientation="-1 0 0 1.571"/>
<Viewpoint DEF="Alto2" description="Alto2" jump="true" fieldOfView="0.785" position="0 200 0" orientation="-1 0 0 1.571"/>
<Viewpoint DEF="Alto3" description="Alto3" jump="true" fieldOfView="0.785" position="0 200 -130" orientation="-1 0 0 1.571"/>
<Transform DEF="dad_Sole" translation="0 50 700" rotation="-1 0 0 .017">
<PointLight DEF="Sole" containerField="children" ambientIntensity="0.000" intensity="1.000" radius="1000.000" attenuation="1 0 0" color="1 1 1" on="true"/>
</Transform>
<Transform DEF="dad_Strada_DX" containerField="children" translation="16 0 0" rotation="1 0 0 1.571">
<Shape DEF="Strada_DX" containerField="children">
<Appearance containerField="appearance">
<Material DEF="Shiny_Black" containerField="material" ambientIntensity="0.200" shininess="0.100" diffuseColor="0 0 0"/>
</Appearance>
<Box DEF="GeoBox1" containerField="geometry" size="35 430 .0001" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Strada_SX" containerField="children" translation="-16 0 0" rotation="1 0 0 1.571">
<Shape DEF="Strada_SX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Shiny_Black"/>
</Appearance>
<Box DEF="GeoBox2" containerField="geometry" size="35 430 .0001" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Riga1_DX" containerField="children" translation="10 .05 0">
<Shape DEF="Riga1_DX" containerField="children">
<Appearance containerField="appearance">
<Material DEF="Shiny_White" containerField="material" ambientIntensity="0.200" shininess="0.100" diffuseColor="1 1 1" specularColor="1 1 1"/>
</Appearance>
<Box DEF="GeoBox8" containerField="geometry" size=".4 .0001 430" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Riga2_DX" containerField="children" translation="20 .05 0">
<Shape DEF="Riga2_DX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Shiny_White"/>
</Appearance>
<Box DEF="GeoBox9" containerField="geometry" size=".4 .0001 430" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Riga3_DX" containerField="children" translation="30 .05 0">
<Shape DEF="Riga3_DX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Shiny_White"/>
</Appearance>
<Box DEF="GeoBox10" containerField="geometry" size=".4 .0001 430" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Riga1_SX" containerField="children" translation="-10 .05 0">
<Shape DEF="Riga1_SX" containerField="children">
<Appearance containerField="appearance">
<Material DEF="material" containerField="material" ambientIntensity="0.200" shininess="0.100" diffuseColor="1 1 1" specularColor="1 1 1"/>
</Appearance>
<Box DEF="GeoBox5" containerField="geometry" size=".4 .0001 430" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Riga2_SX" containerField="children" translation="-20 .05 0">
<Shape DEF="Riga2_SX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Shiny_White"/>
</Appearance>
<Box DEF="GeoBox6" containerField="geometry" size=".4 .0001 430" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Riga3_SX" containerField="children" translation="-30 .05 0">
<Shape DEF="Riga3_SX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Shiny_White"/>
</Appearance>
<Box DEF="GeoBox7" containerField="geometry" size=".4 .0001 430" solid="false"/>
</Shape>
</Transform>
<Transform DEF="dad_Muro" containerField="children" translation="0 0 -215" rotation="1 0 0 1.571">
<Shape DEF="Muro" containerField="children">
<Appearance containerField="appearance">
<Material DEF="Red" containerField="material" ambientIntensity="0.200" shininess="0.200" diffuseColor=".49804 .49804 .49804"/>
</Appearance>
<Extrusion DEF="GeoExtrusion3" containerField="geometry" creaseAngle="0.175" convex="false" crossSection="
.39885 -2.00308
-.40683 -2.00308
-.40683 -2.00308
-.51053 -.99798
-.99712 -.34386
-.99866 0
.99866 0
.99712 -.31993
.50255 -.99798
.39885 -2.00308" spine="
0 0 0
0 430 0"/>
</Shape>
</Transform>
<Transform DEF="dad_Canaletta_DX" containerField="children" translation="34.3999 -.995 215" rotation="0 -.707 .707 3.142">
<Shape DEF="Canaletta_DX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Red"/>
</Appearance>
<NurbsPatchSurface containerField="geometry" solid="false" ccw="false" uDimension="6" vDimension="2" uOrder="4" vOrder="2" uTessellation="-4" vTessellation="1" uKnot="
0
0
0
0
.33333
.66667
1
1
1
1" vKnot="
0
0
1
1">
<Coordinate containerField="controlPoint" point="
-1.98632 0 -.9994
-1.52138 0 -.46432
-1.00835 0 -.46432
-.47764 0 -.46432
0 0 -.99503
.99066 0 -.99503
-1.98632 430 -.9994
-1.52138 430 -.46432
-1.00835 430 -.46432
-.47764 430 -.46432
0 430 -.99503
.99066 430 -.99503"/>
</NurbsPatchSurface>
</Shape>
</Transform>
<Transform DEF="dad_Canaletta_SX" containerField="children" translation="-34.4 -.995 -215" rotation="1 0 0 1.571">
<Shape DEF="Canaletta_SX" containerField="children">
<Appearance containerField="appearance">
<Material containerField="material" USE="Red"/>
</Appearance>
<NurbsPatchSurface containerField="geometry" solid="false" ccw="false" uDimension="6" vDimension="2" uOrder="4" vOrder="2" uTessellation="-4" vTessellation="1" uKnot="
0
0
0
0
.33333
.66667
1
1
1
1" vKnot="
0
0
1
1">
<Coordinate containerField="controlPoint" point="
-1.98632 0 -.9994
-1.52138 0 -.46432
-1.00835 0 -.46432
-.47764 0 -.46432
0 0 -.99503
.99066 0 -.99503
-1.98632 430 -.9994
-1.52138 430 -.46432
-1.00835 430 -.46432
-.47764 430 -.46432
0 430 -.99503
.99066 430 -.99503"/>
</NurbsPatchSurface>
</Shape>
</Transform>
</Transform>
</xsl:template>
</xsl:stylesheet>