Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Creating a table with XSLT [Thread Next] Re: Creating a table with XSLTTo: NULL Date: 3/6/2005 3:14:00 PM
"Joris Gillis" <roac@p...> ha scritto nel messaggio
news:opsm50iqq7yf9v9r@n......
> Tempore 13:01:13, die Saturday 05 March 2005 AD, hinc in foro
{microsoft.public.xsl} scripsit JoKer <ugo+x@l...>:
> Hi,
>
> Supposing that the XML looks like:
>
> <root>
> <n ID="1_1">a</n>
> <n ID="1_3">d</n>
> <n ID="1_4">e</n>
> <n ID="2_1">f</n>
> <n ID="3_5">g</n>
> </root>
>
> and that the according ouput should look like:
> ___________
> |a| |d|e| |
> |f| | | | |
> | | | | |g|
> - - - - -
>
> You can use something like this:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" indent="yes" />
>
> <xsl:key name="field" match="n" use="@ID"/>
>
> <xsl:variable name="maxrow">
> <xsl:apply-templates select="//n" mode="X">
> <xsl:sort select="substring-before(ID,'_')" data-type="number"/>
> </xsl:apply-templates>
> </xsl:variable>
>
> <xsl:variable name="maxcol">
> <xsl:apply-templates select="//n" mode="X">
> <xsl:sort select="substring-after(ID,'_')" data-type="number"/>
> </xsl:apply-templates>
> </xsl:variable>
>
> <xsl:variable name="ColCount"
select="number(substring-after($maxcol,'_'))"/>
> <xsl:variable name="RowCount"
select="number(substring-before($maxrow,'_'))"/>
>
> <xsl:template match="*" mode="X">
> <xsl:if test="position() = last()"><xsl:value-of select="@ID"/></xsl:if>
> </xsl:template>
>
> <xsl:template match="root">
> <table>
> <xsl:call-template name="rows"/>
> </table>
> </xsl:template>
>
> <xsl:template name="rows">
> <xsl:param name="rc" select="1"/>
> <xsl:if test="$rc <= $RowCount">
> <tr>
> <xsl:call-template name="cols">
> <xsl:with-param name="rc" select="$rc"/>
> </xsl:call-template>
> </tr>
> <xsl:call-template name="rows">
> <xsl:with-param name="rc" select="$rc + 1"/>
> </xsl:call-template>
> </xsl:if>
> </xsl:template>
>
> <xsl:template name="cols">
> <xsl:param name="rc"/>
> <xsl:param name="cc" select="1"/>
> <xsl:if test="$cc <= $ColCount">
> <td>
> <xsl:value-of select="key('field',concat($rc,'_',$cc))"/>
> </td>
> <xsl:call-template name="cols">
> <xsl:with-param name="cc" select="$cc + 1"/>
> <xsl:with-param name="rc" select="$rc"/>
> </xsl:call-template>
> </xsl:if>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
>
>
> regards,
> --
Thanx a lot!! I'll try it!
You've been very gentle.
J
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
