Problema transformar con xslt ...
Publicado por lnx (2 intervenciones) el 06/10/2007 12:09:25
Hola buenas ...
Tengo un problemilla a la hora de transformar un xml que quiero que termine siendo xhtml.
A continuacion os pongo un trozo de xml y el xslt de ejemplo de lo que quiero hacer :
XML
<doc>
<head>
<title>Prueba</title>
</head>
<body>
<h1>oeeeee</h1>
<part params="1,2,3,4" />
<div>
<part params="1,2,3,4" />
</div>
</body>
</doc>
------------------------------------------------------
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="UTF-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
<xsl:template match="/">
<xsl:apply-templates select="/doc" />
</xsl:template>
<xsl:template match="doc">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca">
<xsl:apply-templates select="head" />
<xsl:apply-templates select="body" />
</html>
</xsl:template>
<xsl:template match="head">
<head>
<xsl:copy-of select="*" />
</head>
</xsl:template>
<xsl:template match="body">
<body>
<xsl:apply-templates />
</body>
</xsl:template>
<xsl:template match="part">
<xsl:value-of
disable-output-escaping="yes" select="php:function('constructGetDoc',string(@params))"/>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------------------------
Bueno lo que quiero conseguir es que al transformar el xml todos los tags incluidos dentro de body tambien esten en el documento transformado, no como ahora que por ejemplo el tag h1 no lo incluye, si no que solo incluye su valor, esto quiero que pase con cualquier tag que sea distinto de part.
Os pongo como queda la transformacion ahora :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca" lang="ca">
<head xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Prueba</title>
</head>
<body xmlns="">
oeeeee
<!-- RESULTADO DE TRANSFORMAR EL TAG PART -->
<!-- RESULTADO DE VOLVER A TRANSFORMAR EL TAG PART -->
</body>
</html>
Y continuacion como quiero que quede :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca" lang="ca">
<head xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Prueba</title>
</head>
<body xmlns="">
<h1>oeeeee</h1>
<!-- RESULTADO DE TRANSFORMAR EL TAG PART -->
<div>
<!-- RESULTADO DE VOLVER A TRANSFORMAR EL TAG PART -->
</div>
</body>
</html>
Bueno, gracias de antemano ...
Tengo un problemilla a la hora de transformar un xml que quiero que termine siendo xhtml.
A continuacion os pongo un trozo de xml y el xslt de ejemplo de lo que quiero hacer :
XML
<doc>
<head>
<title>Prueba</title>
</head>
<body>
<h1>oeeeee</h1>
<part params="1,2,3,4" />
<div>
<part params="1,2,3,4" />
</div>
</body>
</doc>
------------------------------------------------------
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="UTF-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
<xsl:template match="/">
<xsl:apply-templates select="/doc" />
</xsl:template>
<xsl:template match="doc">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca">
<xsl:apply-templates select="head" />
<xsl:apply-templates select="body" />
</html>
</xsl:template>
<xsl:template match="head">
<head>
<xsl:copy-of select="*" />
</head>
</xsl:template>
<xsl:template match="body">
<body>
<xsl:apply-templates />
</body>
</xsl:template>
<xsl:template match="part">
<xsl:value-of
disable-output-escaping="yes" select="php:function('constructGetDoc',string(@params))"/>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------------------------
Bueno lo que quiero conseguir es que al transformar el xml todos los tags incluidos dentro de body tambien esten en el documento transformado, no como ahora que por ejemplo el tag h1 no lo incluye, si no que solo incluye su valor, esto quiero que pase con cualquier tag que sea distinto de part.
Os pongo como queda la transformacion ahora :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca" lang="ca">
<head xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Prueba</title>
</head>
<body xmlns="">
oeeeee
<!-- RESULTADO DE TRANSFORMAR EL TAG PART -->
<!-- RESULTADO DE VOLVER A TRANSFORMAR EL TAG PART -->
</body>
</html>
Y continuacion como quiero que quede :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca" lang="ca">
<head xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Prueba</title>
</head>
<body xmlns="">
<h1>oeeeee</h1>
<!-- RESULTADO DE TRANSFORMAR EL TAG PART -->
<div>
<!-- RESULTADO DE VOLVER A TRANSFORMAR EL TAG PART -->
</div>
</body>
</html>
Bueno, gracias de antemano ...
Valora esta pregunta


0