Italian student working on XSLT... please help me!

Here should go questions about transforming XML with XSLT and FOP.
guastoboy
Posts: 3
Joined: Mon Feb 20, 2006 6:37 pm

Italian student working on XSLT... please help me!

Post by guastoboy » Mon Feb 20, 2006 7:03 pm

hi y'll I'm an Italian student, (so pardon my bad English!)..I'm in a very hurry now, cos I gotta finish a project for a prof very soon, and I don't know how to do...
I've almost done it, it's about "translate" some texts in TEI "lite", I've also almost done all the XSLT's but I just have one last problem.. here down you can see what I need



that's the code I made with XML-TEI "Lite"
it's something like Italian poetry.. so you know what I mean, verses, line numbers and so on..

...
<lg>
<l>Ripiene, accompagnate, e copiose,</l>
<l>Gloria de l'età d'oro; degne certo</l>
<l>Che la città vi invidii, poiché in quella</l>
<l>Non è quiete vera, non è vita,</l>
<l>Ma agitata di cure, e d'onor lievi,</l>
<num>10</num>
<l>Una bulla di vento, ove che giova</l>
<l>Viver, né poi saper come si vive?</l>
<l>Molti che son famosi e noti al mondo</l>
<l>Morono in fine a sé medesmi ignoti,</l>
<l>E sol resta di fama un roco suono.</l>
<num>15</num>
<l>In questi, non orror, ma lieti aspetti</l>
<l>Di boscareccie fronde non perviene</l>
</lg>


my very problem is that I don't know how to make an XSLT in order to make the number in the "<num>" tag stay in the same line of the previous "<l>" tag..

I mean, something like this.. (next you can see the visualization I need to have)


Ripiene, accompagnate, e copiose,
Gloria de l'età d'oro; degne certo
Che la città vi invidii, poiché in quella
Non è quiete vera, non è vita,
Ma agitata di cure, e d'onor____________________10
Una bulla di vento, ove che giova
Viver, né poi saper come si vive?
Molti che son famosi e noti al mondo
Morono in fine a sé medesmi ignoti,
E sol resta di fama un roco suono.______________15
In questi, non orror, ma lieti aspetti
Di boscareccie fronde non perviene
Romor di fiera tromba, o d'armi scosse,
Non è di sangue uman bagnato il suolo,
Non si sentono qui discordie o liti,_______________20


please.. help me.. it will make me the happiest guy if you can help me finish all this stuff!!

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Wed Feb 22, 2006 11:35 am

Hi,

On a document like

Code: Select all


<lg>
<l>Ripiene, accompagnate, e copiose,</l>
<l>Gloria de l'età d'oro; degne certo</l>
<l>Che la città vi invidii, poiché in quella</l>
<l>Non è quiete vera, non è vita,</l>
<l>Ma agitata di cure, e d'onor lievi,</l>
<num>10</num>
<l>Una bulla di vento, ove che giova</l>
<l>Viver, né poi saper come si vive?</l>
<l>Molti che son famosi e noti al mondo</l>
<l>Morono in fine a sé medesmi ignoti,</l>
<l>E sol resta di fama un roco suono.</l>
<num>15</num>
<l>In questi, non orror, ma lieti aspetti</l>
<l>Di boscareccie fronde non perviene</l>
</lg>
the following stylesheet

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="lg">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="l">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="l[following-sibling::*[1][self::num]]" priority="5">
<xsl:variable name="spaces" select="80 - string-length(.) - string-length(following-sibling::*[1])"/>
<xsl:value-of select="."/>
<xsl:call-template name="printSpaces">
<xsl:with-param name="count" select="$spaces"/>
</xsl:call-template>
<xsl:value-of select="following-sibling::*[1]"/>
</xsl:template>

<xsl:template name="printSpaces">
<xsl:param name="count" select="0"/>
<xsl:if test="$count>0">
<xsl:text> </xsl:text>
<xsl:call-template name="printSpaces">
<xsl:with-param name="count" select="$count - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
will give you

Code: Select all


  1--------10--------20--------30--------40--------50--------60--------70--------80--
Ripiene, accompagnate, e copiose,
Gloria de l'età d'oro; degne certo
Che la città vi invidii, poiché in quella
Non è quiete vera, non è vita,
Ma agitata di cure, e d'onor lievi, 10

Una bulla di vento, ove che giova
Viver, né poi saper come si vive?
Molti che son famosi e noti al mondo
Morono in fine a sé medesmi ignoti,
E sol resta di fama un roco suono. 15

In questi, non orror, ma lieti aspetti
Di boscareccie fronde non perviene

Best Regards,
George

guastoboy
Posts: 3
Joined: Mon Feb 20, 2006 6:37 pm

Post by guastoboy » Wed Mar 01, 2006 10:49 am

mmh.. thank you! anyway, that's not what exactly i was looking for.. anyway, maybe now i can be more specific..

Code: Select all

<lg> 
<l type "capoverso">Ripiene, accompagnate, e copiose,</l>
<l>Gloria de l'età d'oro; degne certo</l>
<l>Che la città vi invidii, poiché in quella</l>
<l>Non è quiete vera, non è vita,</l>
<l>Ma agitata di cure, e d'onor lievi,</l>
<num>10</num>
<l>Una bulla di vento, ove che giova</l>
<l>Viver, né poi saper come si vive?</l>
<l type="capoverso">Molti che son famosi e noti al mondo</l>
<l>Morono in fine a sé medesmi ignoti,</l>
<l>E sol resta di fama un roco suono.</l>
<num>15</num>
<l>In questi, non orror, ma lieti aspetti</l>
<l>Di boscareccie fronde non perviene</l>
</lg>
as you can see the tag <lg> is the father of the different tags <l> and <num>
there are 2 different <l> tags ---> <l> and <l type="capoverso"> and a <num> tag

i tried with xslt but i can't have what i want to..

the following is the code i will like to have in html after xslt stylesheet..

Code: Select all

<div class="sp">
<div style="...">Ripiene, accompagnate, e copiose,</div>
<div style="...">Gloria de l'età d'oro; degne certo</div>
<div style="...">Che la città vi invidii, poiché in quella</div>
...
..
<div style="...">10</div>
<div style="...">Una bulla di vento, ove che giova</div>
<div style="...">Viver, né poi saper come si vive?</div>
..
..
..
<div style="...">15</div>
<div style="...">In questi, non orror, ma lieti aspetti</div>
<div style="...">Di boscareccie fronde non perviene</div>
</div>
i think i should do something in xslt with if or whatevere else... please, help me!

Ciao!

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Wed Mar 01, 2006 5:11 pm

Hi,

In that case the solution is simpler:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/lg">
<div class="sp">
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="l|num">
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
<xsl:otherwise><xsl:value-of select="name()"/></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</div>
</xsl:template>
</xsl:stylesheet>
Note the choose used to specify the value of the class attribute for l elements.

In XSLT 2.0 that will be:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/lg">
<div class="sp"><xsl:apply-templates /></div>
</xsl:template>
<xsl:template match="l|num">
<div class="{if (@type) then @type else name()}">
<xsl:value-of select="." />
</div>
</xsl:template>
</xsl:stylesheet>
Best Regards,
George

Post Reply