xml - Why do i get no formatted result (csv) with my xsl? -
how can give output correct format? missing in xslt? @ example below. thank in advance help.
xml:
<?xml version="1.0" encoding="utf-8"?> <fed xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <poi> <id>56241</id> <poi_contact> <categoryid>museum</categoryid> <name>centre pompidou</name> </poi_contact> </poi> <poi> <id>141670</id> <poi_contact> <categoryid>museum</categoryid> <name>espace culturel saint-exupéry</name> </poi_contact> </poi> <poi> <id>56242</id> <poi_contact> <categoryid>museum</categoryid> <name>musée du louvre</name> </poi_contact> </poi> </fed>
xsl:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="text" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> id;category;name <xsl:for-each select="fed/poi"> <xsl:value-of select="id"/>; <xsl:value-of select="poi_contact/categoryid"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
output:
id;category;name 56241; museum 141670; museum 56242; museum
the output should this:
id;category;name
56241;museum
141670;museum
56242;museum
the problem specifying literal text have entire text node, including surrounding white spaces, passed output.
try instead:
<xsl:template match="/"> <xsl:text>id;category;name </xsl:text> <xsl:for-each select="fed/poi"> <xsl:value-of select="id"/> <xsl:text>;</xsl:text> <xsl:value-of select="poi_contact/categoryid"/> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
p.s. header says id;category;name
, not outputting name
.
Comments
Post a Comment