[xsl] how to change value of attributes

Subject: [xsl] how to change value of attributes
From: "ivanmacculi\@libero\.it" <ivanmacculi@xxxxxxxxx>
Date: Wed, 25 Nov 2009 17:26:06 +0100
Hi all, i'm a librarian with a problem: i've to change the value of attri=
bute for each element of a group that i'm not able to select and count.
i've something like this:

<mets:div LABEL=3D"Testo" ORDER=3D"4" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Frontespizio" ORDER=3D"1" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Pagina 5" ORDER=3D"1" ORDERLABEL=3D"5">
<mets:fptr FILEID=3D"file.00008"/>
</mets:div>
</mets:div>
<mets:div LABEL=3D"Dedica" ORDER=3D"2" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Pagina 6" ORDER=3D"1" ORDERLABEL=3D"6">
<mets:fptr FILEID=3D"file.00009"/>
</mets:div>
</mets:div>
<mets:div LABEL=3D"Canto I" ORDER=3D"3" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Pagina 7" ORDER=3D"1" ORDERLABEL=3D"7">
<mets:fptr FILEID=3D"file.00010"/>
</mets:div>
<mets:div LABEL=3D"Pagina 8" ORDER=3D"2" ORDERLABEL=3D"8">
<mets:fptr FILEID=3D"file.00011"/>
</mets:div>
<mets:div LABEL=3D"Pagina 9" ORDER=3D"3" ORDERLABEL=3D"9">
<mets:fptr FILEID=3D"file.00012"/>
</mets:div>
</mets:div>
</mets:div>

i have to change the value of LABEL from "pagina 5, pagina 6, pagina 7, p=
agina 8, etc..." to "carta 1r, carta 1v, carta 2r, carta 2v, etc".
So the problem is that i've a order of pages with a kind of enumeration, =
and it will became a list of a double enumeration. each number is repeate=
d.
It will be something like this:

<mets:div LABEL=3D"Testo" ORDER=3D"4" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Frontespizio" ORDER=3D"1" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Carta 1r" ORDER=3D"1" ORDERLABEL=3D"5">
<mets:fptr FILEID=3D"file.00008"/>
</mets:div>
</mets:div>
<mets:div LABEL=3D"Dedica" ORDER=3D"2" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Carta 1v" ORDER=3D"1" ORDERLABEL=3D"6">
<mets:fptr FILEID=3D"file.00009"/>
</mets:div>
</mets:div>
<mets:div LABEL=3D"Canto I" ORDER=3D"3" ORDERLABEL=3D"1">
<mets:div LABEL=3D"Carta 2r" ORDER=3D"1" ORDERLABEL=3D"7">
<mets:fptr FILEID=3D"file.00010"/>
</mets:div>
<mets:div LABEL=3D"Carta 2v" ORDER=3D"2" ORDERLABEL=3D"8">
<mets:fptr FILEID=3D"file.00011"/>
</mets:div>
<mets:div LABEL=3D"Carta 3r" ORDER=3D"3" ORDERLABEL=3D"9">
<mets:fptr FILEID=3D"file.00012"/>
</mets:div>
</mets:div>
</mets:div>


in another occasion i prepared this .xsl, but in that case <mets:div LABE=
L=3D"Pagina #"> was subelement of text and not subelement of another elem=
ent. so this's my problem.


<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xsl:stylesheet exclude-result-prefixes=3D"#all" version=3D"2.0"
xmlns:mets=3D"http://www.loc.gov/METS/"; xmlns:mix=3D"http://www.loc.gov/m=
ix/" xmlns:xlink=3D"http://www.w3.org/1999/xlink";
xmlns:rd=3D"http://cosimo.stanford.edu/sdr/metsrights/"; xmlns:xsl=3D"http=
://www.w3.org/1999/XSL/Transform">


<xsl:output indent=3D"yes" method=3D"xml"/>

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


<xsl:template match=3D"mets:div[@LABEL=3D'Testo']/mets:div[position() mod=
2 =3D 1]">
<xsl:copy>
<xsl:apply-templates select=3D"@*"/>
<xsl:attribute name=3D"LABEL">
<xsl:text>Carta [</xsl:text><xsl:number count=3D"mets:div[@LABEL=3D'Testo=
']/mets:div[position() mod 2 =3D 1]" format=3D"1"/>r]</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match=3D"mets:div[@LABEL=3D'Testo']/mets:div[position() mod=
2 =3D 0]">
<xsl:copy>
<xsl:apply-templates select=3D"@*"/>
<xsl:attribute name=3D"LABEL">
<xsl:text>Carta [</xsl:text><xsl:number count=3D"mets:div[@LABEL=3D'Testo=
']/mets:div[position() mod 2 =3D 0]" format=3D"1"/>v]</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>


<xsl:template match=3D"mets:div[@LABEL=3D'Fogli di guardia posteriori']/m=
ets:div">
<xsl:copy>
<xsl:apply-templates select=3D"@*"/>
<xsl:attribute name=3D"LABEL">
<xsl:number count=3D"mets:div[@LABEL=3D'Fogli di guardia posteriori']/met=
s:div" format=3D"I"/></xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

thanks a lot to everyone.

Current Thread