Eliminar espacios de elementos XML
Frecuentes
Visto 201 veces
2
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?
2 Respuestas
5
<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
0
<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 xslt or haz tu propia pregunta.