xsl-list
[Top] [All Lists]

Re: Coma delimited values in attribute

2005-09-16 22:22:12
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(_at_)biplane(_dot_)ru> 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:

+--------+-----+---+-----+
| tarif1 | str | 1 | 152 |
+--------+-----+---+-----+
| tarif2 | cur | 1 | 100 |
+--------+-----+---+-----+
| tarif3 | str | 1 | 252 |
+--------+-----+---+-----+
| tarif4 | cur | 1 | 203 |
+--------+-----+---+-----+

--
Best regards, Belousov Alexey

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>