[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Coma delimited values in attribute

Subject: Re: Coma delimited values in attribute
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Sat, 17 Sep 2005 10:52:12 +0530
xslt delimited
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 &gt; 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.