Subject: Re: [xsl] Coma delimited values in attribute From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx> Date: Sat, 17 Sep 2005 10:52:12 +0530 |
You could try this XSLT 2.0 stylesheet(tested with Saxon 8.5.1). I have tried to make it generic. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="html" indent="yes" /> <xsl:template match="/Fields"> <html> <head> <title/> </head> <table> <xsl:variable name="n" select="string-length(field[1]/@value) - string-length(translate(field[1]/@value,',','')) + 1" /> <xsl:variable name="field" select="field" /> <xsl:for-each select="1 to $n"> <tr> <xsl:call-template name="generateTD"> <xsl:with-param name="field" select="$field" /> <xsl:with-param name="delim" select="','" /> <xsl:with-param name="x" select="position()" /> </xsl:call-template> </tr> </xsl:for-each> </table> </html> </xsl:template> <xsl:template name="generateTD"> <xsl:param name="field" /> <xsl:param name="delim" /> <xsl:param name="x" /> <xsl:for-each select="$field"> <td> <xsl:call-template name="extractvalue"> <xsl:with-param name="value" select="@value" /> <xsl:with-param name="delim" select="$delim" /> <xsl:with-param name="x" select="$x" /> </xsl:call-template> </td> </xsl:for-each> </xsl:template> <xsl:template name="extractvalue"> <xsl:param name="value" /> <xsl:param name="delim" /> <xsl:param name="x" /> <xsl:choose> <xsl:when test="$x > 1"> <xsl:call-template name="extractvalue"> <xsl:with-param name="value" select="substring-after($value,$delim)" /> <xsl:with-param name="delim" select="$delim" /> <xsl:with-param name="x" select="$x - 1" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="contains($value,$delim)"> <xsl:value-of select="substring-before($value,$delim)" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$value" /> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Regards, Mukul On 9/16/05, Belousov Alexey <web@xxxxxxxxxx> wrote: > Hello all. > I'm a bit new to XSL and currently having a problem. Any help would be > greately apreciated. > > I have the following XML: > > -------[XML]------------------------------------------------------------ > <Fields> > <field name="tarifSelect" value="tarif1,tarif2,tarif3,tarif4" /> > <field name="numberType" value="str,cur,str,cur" /> > <field name="cardsNum" value="1,1,1,1" /> > <field name="price" value="152,100,252,203" /> > </Fields> > ------------------------------------------------------------------------ > > I want it to be representd as a HTML table like:
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Coma delimited values in , Belousov Alexey | Thread | Re: [xsl] Coma delimited values in , andrew welch |
Re: [xsl] Total occurences and orde, António Mota | Date | Re: [xsl] Coma delimited values in , andrew welch |
Month |