0

I want to recover proper names (name) of an XML through XSLT, but under condition that whatever is in ex is printed in italics.

This is the XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
    schematypens="http://purl.oclc.org/dsdl/schematron"?>
<?xml-stylesheet type="text/xsl" href="textocorto.xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <teiHeader>
        <fileDesc>
            <titleStmt>
                <title>Title</title>
            </titleStmt>
            <publicationStmt>
                <p>Publication Information</p>
            </publicationStmt>
            <sourceDesc>
                <p>Information about the source</p>
            </sourceDesc>
        </fileDesc>
    </teiHeader>
    <text>
        <body>
            <pb n="001r"/>
            <div1 type="book" n="01">
                
                <div2 type="chapter" n="000">
                    <cb n="a"/>
                    <head> Capítulo 1 </head>
                    <ab> Este es el texto del capítulo 1 de la columna A del folio 1r y le pongo dos
                        nombrecitos <name>Don alfo<ex>ns</ex>so</name> y otro nombrecillo para no perdernos doña
                        <name>beatriz</name>
                    </ab>
                </div2>
                <div2>
                    <cb n="b"/>
                    <head>Capítulo II </head>
                    
                    <ab>Este es el texto del capítulo II, que se encuentra en la columba B del folio 1r.
                        Y vamos a poner unos nombres: don <name>al<ex>fon</ex>so</name>, doña <name>Urraca</name>
                    </ab>
                </div2>
                <pb n="001v"/>
                <div2>
                    <head>Capítulo III</head>
                    <ab> Este es el texto del capítulo 3. Vamos a poner tres nombres:
                        <name>Fer<ex>nan</ex>do</name>, <name>Le<ex>tic</ex>ia</name> e <name>I<ex>s</ex>a</name>
                    </ab>
                </div2>
                            </div1>
        </body>
    </text>
</TEI>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:tei="http://www.tei-c.org/ns/1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html lang="es">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                
            </head>
            <body>
                <h1>Nombres propios</h1>
                <xsl:for-each select="tei:TEI//tei:name">
                    <p/>
                    <xsl:apply-templates select="/tei:TEI/tei:text/tei:body/tei:pb"/>,
                    <xsl:apply-templates select="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2/tei:cb"/>
                    <xsl:apply-templates select="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2"/>
                    
                </xsl:for-each>
            </body>
            
        </html>
    </xsl:template>
    
    <xsl:template match="/tei:TEI/tei:text/tei:body/tei:pb">
        <xsl:for-each select="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2/tei:ab/tei:name"/>
        <xsl:value-of select="@n"/>: <xsl:value-of
            select="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2/tei:ab/tei:name"/>
        
    </xsl:template>
    <xsl:template match="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2/tei:cb">
        <xsl:for-each select="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2/tei:ab/tei:name"/>
        <xsl:value-of select="@n"/>
        
        
    </xsl:template>
    <xsl:template match="/tei:TEI/tei:text/tei:body/tei:div1/tei:div2">
        <xsl:for-each select="/tei:TEI/tei:text//tei:div1/tei:div2/tei:ab/tei:name"/>
        <xsl:value-of select="@n"/>
    </xsl:template>  
</xsl:stylesheet>

Thanks!

Miguel LH
  • 15
  • 3

2 Answers2

0

Why not simply:

XSLT 1.0

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="tei">
<xsl:output method="html"/>

<xsl:template match="/">
    <html>
        <body>
            <h1>Nombres propios</h1>
            <xsl:apply-templates select="//tei:name"/>
        </body>
    </html>
</xsl:template>

<xsl:template match="tei:name">
    <p>
        <xsl:apply-templates/>
    </p>
</xsl:template>

<xsl:template match="tei:ex">
    <i>
        <xsl:apply-templates/>
    </i>
</xsl:template>  

</xsl:stylesheet>

Applied to your input example, the result will be:

<html>
<body>
<h1>Nombres propios</h1>
<p>Don alfo<i>ns</i>so</p>
<p>beatriz</p>
<p>al<i>fon</i>so</p>
<p>Urraca</p>
<p>Fer<i>nan</i>do</p>
<p>Le<i>tic</i>ia</p>
<p>I<i>s</i>a</p>
</body>
</html>

rendered as:

enter image description here

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
0

Thank you very much, @michael.hor257k I'm philologist and I just started to know this kind of syntax. Thanks and Sorry to bother you again, but yesterday I changed some things and organized the stylesheet in a table. To get the same, how could I put it on the table?

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
    schematypens="http://purl.oclc.org/dsdl/schematron"?>


<?xml-stylesheet type="text/xsl" href="1.antroponimoscopia.xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <teiHeader>
        <fileDesc>
            <titleStmt>
                <title>Title</title>
            </titleStmt>
            <publicationStmt>
                <p>Publication Information</p>
            </publicationStmt>
            <sourceDesc>
                <p>Information about the source</p>
            </sourceDesc>
        </fileDesc>
    </teiHeader>
    <text>
        <body>
            <pb n="001r"/>
            <div1 type="book" n="01">
                
                <div2 type="chapter" n="000">
                    <cb n="a"/>
                    <head> Capítulo 1 </head>
                    <ab> Este es el texto del capítulo 1 de la columna A del folio 1r y le pongo dos
                        nombrecitos <name type="proper">Don alfo<ex>ns</ex>so</name> y otro nombrecillo para no perdernos doña
                        <name type="proper">beatriz</name>
                    </ab>
                </div2>
                <div2 type="chapter" n="001">
                    <cb n="b"/>
                    <head>Capítulo II </head>
                    
                    <ab>Este es el texto del capítulo II, que se encuentra en la columba B del folio 1r.
                        Y vamos a poner unos nombres: don <name type="proper">al<ex>fon</ex>so</name>, doña <name type="proper">Urraca</name>
                    </ab>
                </div2>
                <pb n="001v"/>
                <div2 type="chapter" n="002">
                    <head>Capítulo III</head>
                    <ab> Este es el texto del capítulo 3. Vamos a poner tres nombres:
                        <name type="proper">Fer<ex>nan</ex>do</name>, <name type="proper">Le<ex>tic</ex>ia</name> e <name type="proper">I<ex>s</ex>a</name>
                    </ab>
                </div2>
            </div1>
        </body>
    </text>
</TEI>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:tei="http://www.tei-c.org/ns/1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html lang="es">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            </head>
            <body>
                <h3 align="center">
                    <b>Antropónimos</b>
                </h3>
                <table width="750" border="1" align="center">
                    <tr>
                        <th scope="col" bgcolor="#00CCFF">
                            <div align="center">Nombre</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF">
                            <div align="center">Libro</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF">
                            <div align="center">Capítulo</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF">
                            <div align="center">Folio</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF">
                            <div align="center">Columna</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF">
                            <div align="center">Línea</div>
                        </th>
                    </tr>

                    <tr>

                        <td>
                            <xsl:for-each select="//tei:name[@type='proper']">
                                <div align="center">
                                    <xsl:value-of select="."/>
                                </div>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:name[@type='proper']">
                                <div align="center">
                                    <xsl:value-of select="ancestor::tei:div1/@n"/>
                                </div>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:name[@type='proper']">
                                <div align="center">
                                    <xsl:value-of select="ancestor::tei:div2/@n"/>
                                </div>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="tei:name[@type='proper']">
                                <div align="center">
                                    <xsl:value-of select="preceding::tei:pb[@n][1]/@n"/>
                                </div>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:name[@type='proper']">
                                <div align="center">
                                    <xsl:value-of select="preceding::tei:cb[@n][1]/@n"/>
                                </div>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:name[@type='proper']">
                                <div align="center">
                                    <xsl:value-of select="preceding::tei:lb[@n][1]/@n"/>
                                </div>
                            </xsl:for-each>
                        </td>
                    </tr>
                </table>
            </body>
        </html>

    </xsl:template>



</xsl:stylesheet>

Thanks!!

Miguel LH
  • 15
  • 3