[oXygen-user] how to change value of attributes


Wed Nov 25 10:19:13 CST 2009


Hi all, i'm a librarian with a problem: i've to change the value of attribute for each element of a group that i'm not able to select and count.
i've something like this:

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

i have to change the value of LABEL from "pagina 5, pagina 6, pagina 7, pagina 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 repeated. 
It will be something like this:  

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


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


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


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

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


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

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


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

</xsl:stylesheet>

thanks a lot to everyone. 




More information about the oXygen-user mailing list