из этого кода я хотел бы извлечь два запроса в виде результатов XSLT, которые должны выглядеть так:
<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. Любая помощь будет действительно полезной.
Используйте этот код
Таблица 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 = "&#x00F3;"/>
<xsl:output-character character = "ñ" string = "&#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>
child::*
илиchild::nombre
илиchild::creator
то же самое, что*
илиnombre
илиcreator
: ось ребенок — это ось по умолчанию в пути местоположения.