使用斜体 XSLT 恢复信息 XML

Recover information XML with XSLT in italic

我想通过 XSLT 恢复 XML 的专有名称 (name),但条件是 ex 中的任何内容都以斜体显示。

这是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>

谢谢!

为什么不简单:

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>

应用于您的输入示例,结果将是:

<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>

呈现为:

非常感谢,@michael.hor257k 我是语言学家,我才刚刚开始了解这种语法。谢谢,很抱歉再次打扰你,但昨天我改变了一些东西并将样式表组织在 table 中。要得到相同的,我怎么能把它放在 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>

谢谢!!