Eliminar espacios de elementos XML

Tengo el siguiente XML

<list>
    <foo attr1="value" attr2="red"> </foo>
    <foo attr1="xx" attr2="blue"> </foo>
    <foo attr1="yy" attr2="green"> </foo>
</list>

que quiero llegar a ser:

<list>
    <foo attr1="value" attr2="red"/>
    <foo attr1="xx" attr2="blue"/>
    <foo attr1="yy" attr2="green"/>
</list>

¿Existe una opción XSLT para eliminar los espacios de los nodos foo?

preguntado el 10 de marzo de 12 a las 00:03

2 Respuestas

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
<xsl:strip-space elements="foo"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

respondido 10 mar '12, 00:03

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <!--Identity template copies all content -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <!--If the foo/text() is only whitespace, don't include in output-->
    <xsl:template match="foo/text()[not(normalize-space())]"/>

</xsl:stylesheet>

respondido 10 mar '12, 18:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.