Getting all datas from xml through xslt -
Getting all datas from xml through xslt -
this xslt:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <graph> <categories> <category> <xsl:attribute name="name"> <xsl:value-of select="rows/row/@date" /> </xsl:attribute> </category> </categories> <dataset> <xsl:attribute name="seriesname"> <xsl:value-of select="rows/row/@actual_amount"/> </xsl:attribute> </dataset> <dataset> <xsl:attribute name="seriesname"> <xsl:value-of select="rows/row/@threshold"/> </xsl:attribute> </dataset> <dataset> <xsl:attribute name="seriesname"> <xsl:value-of select="rows/row/@forecast_amount"/> </xsl:attribute> </dataset> </graph> </xsl:template>
this result:
<graph> <categories> <category name="2014-01-01"/> </categories> <dataset seriesname="1800.0000"/> <dataset seriesname="500.0000"/> <dataset seriesname="2800.0000"/> </graph>
can tell me why getting first info of many xml please? have tried putting <xsl:value-of select="."/>
too... first info generated. please help.
i guessing xml looks this:
<rows> <row date="2014-01-01" actual_amount="1800.0000" threshold="500.0000" forecast_amount="2800.0000" /> <row date="2014-01-02" actual_amount="1850.0000" threshold="550.0000" forecast_amount="2850.0000" /> </rows>
you getting first info because start off matching "document node"
<xsl:template match="/">
this called once, code in template beingness output once. additionally, this
<xsl:value-of select="rows/row/@date" />
the value-of statement homecoming value of first node finds matches, regardless of how many rows there are.
you want alter first template this
<xsl:template match="/"> <xsl:apply-templates select="rows/row" /> </xsl:template>
then alter existing template match row instead...
<xsl:template match="row"> <graph> ...
try xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="rows/row" /> </xsl:template> <xsl:template match="row"> <graph> <categories> <category name="{@date}" /> </categories> <dataset seriesname="{@actual_amount}"/> <dataset seriesname="{@threshold}"/> <dataset seriesname="{@forecast_amount}"/> </graph> </xsl:template> </xsl:stylesheet>
do note utilize of attribute value templates in outputting name , seriesname attributes. curly braces { }
indicate look evaluated, not output literally.
also note within template matches row xpath expressions relative current row node matching, have @date
example, , not rows\row\@date
if not quite output want, please edit question show expect, should point in right direction.
xml xslt
Comments
Post a Comment