[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Coma delimited values in attribute
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:
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|