首页 > 解决方案 > 使用斜体的 XSLT 恢复信息 XML

问题描述

我想name通过 XSLT 恢复 XML 的专有名称 (),但条件是其中的任何内容都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>

谢谢!

标签: xmlxsltitalic

解决方案


非常感谢,@michael.hor257k 我是语言学家,我刚刚开始了解这种语法。谢谢,很抱歉再次打扰您,但昨天我更改了一些内容并将样式表组织在一个表格中。为了得到同样的东西,我怎么能把它放在桌子上?

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

谢谢!!


推荐阅读