Jak w XSLT usunąć puste węzły XML’a?
Problem: Mamy XML: <root> <category>Biznes</category> <category> </category> <category></category> <category>Hobby</category> </root> Poprzez transformacje XSLT, chcemy usunąć puste węzły kategorii. Rozwiązanie: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:template match=”/”> <root> <xsl:for-each select=”category”> <xsl:if test=”normalize-space(.)=””> <category> <![CDATA[<xsl:value-of disable-output-escaping=”yes” select=”normalize-space(.)” />]]> </category> </xsl:if> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet> Wyjaśnienie: Instrukcja match=”/” wybiera wszystkie węzły XML’a Instrukcja for-each iteruje po wszystkich węzłach o nazwie … Czytaj dalej „Jak w XSLT usunąć puste węzły XML’a?”