标记名称为文本和表格标签 repetition on XSLT

问题描述 投票:0回答:1

从这段代码我想提取两个查询作为XSLT结果应该如下所示:

This one is the first one

This is the second one

<lenguajes fuente="http://www.wikipedia.org" fecha="2012">
<lenguaje>
    <nombre>C</nombre>
    <creador>Dennis Ritchie</creador>
    <fecha>1973</fecha>
    <compilado />
</lenguaje>
<lenguaje>
    <nombre>Python</nombre>
    <creador>Guido van Rossum</creador>
    <fecha>1991</fecha>
    <interpretado />
</lenguaje>
<lenguaje>
    <nombre>PHP</nombre>
    <creador>Rasmus Lerdorf</creador>
    <fecha>1995</fecha>
    <interpretado />
</lenguaje>
<lenguaje>
    <nombre>XSLT</nombre>
    <creador>James Clark</creador>
    <fecha>1998</fecha>
    <interpretado />
</lenguaje>

这是我到目前为止:

对于第一个:

   <xsl:template match="lenguaje">
    <html>
        <table border="1">
            <tr>
                <th>Lenguaje</th>
                <th>Creador</th>
            </tr>
            <tr>
                <td><xsl:value-of select="nombre"/></td>
                <td><xsl:value-of select="creador"/></td>
            </tr>                
        </table>
    </html>
</xsl:template>

而对于第二个:

   <xsl:template match="lenguaje">
        <html>
            <p>El lenguaje <xsl:value-of select="nombre"/> es </p>
        </html>
</xsl:template>
<xsl:template match="lenguajes">
    <html>
        <p>Información obtenida de <xsl:value-of select="@fuente" /> en el año <xsl:value-of select="@fecha" /></p>
    </html>
</xsl:template>

但它并不适合。因为我自己研究这种事情,我没有找到任何人所需要的帮助。所以这是XML代码。任何帮助都会非常有帮助。

xml xslt
1个回答
0
投票

使用此代码 表格1:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output method="html" omit-xml-declaration="yes"/>
    <xsl:template match="lenguajes">
        <html>
            <head>
                <title></title>
            </head>
            <body>
                <table border="1">
                    <tr>
                        <th>Lenguaje</th>
                        <th>Creador</th>
                    </tr>
                    <xsl:for-each select="lenguaje">
                        <tr>
                            <td><xsl:value-of select="child::nombre"/></td>
                            <td><xsl:value-of select="child::creador"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

表2:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:character-map name="ST">
        <xsl:output-character character="ó" string="&amp;#x00F3;"/>
        <xsl:output-character character="ñ" string="&amp;#x00F1;"/>
    </xsl:character-map>
    <xsl:output method="html" omit-xml-declaration="yes" use-character-maps="ST"/>
    <xsl:template match="lenguajes">
        <html>
            <xsl:for-each select="lenguaje">
                <p>EL <xsl:value-of select="local-name()"/><xsl:text> </xsl:text> <xsl:value-of select="child::nombre"/> es <xsl:value-of select="child::*[last()]/local-name()"/>.</p>
            </xsl:for-each>
            <p>Información obtenida de <xsl:value-of select="@fuente"/> en el año <xsl:value-of select="@fecha"/></p>
        </html>
    </xsl:template>
</xsl:stylesheet>
© www.soinside.com 2019 - 2024. All rights reserved.