This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Stylesheets > August 2006 > newbie xsl / xslt question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
newbie xsl / xslt question
|
|
| dbahooker@hotmail.com 2006-08-28, 6:39 pm |
| Team;
I'm kindof a newbie around these parts :)
I'm trying to replace TAB characters ( ) with </TD><TD>.. so that I
can properly align this XML into multiple cells in a table.
yes-- right now it is living as XML, tab delimited data.. and I want to
push it into 5 different cells.
here is the result: it's displaying this in IE instead of under view
source:
0.1</td><td>29-Sep-2004</td><td>Draft</td><td>Dba
Hooker</td><td>Initial Draft0
under view / source; it's displaying a similiar thing but it shows up
as HTML tags; instead of as HTML source.
thanks SO much for your help guys!!
here is my template call
--------------------------------------------------------------------
<xsl:template match="Property[@name='CHistory']">
<xsl:call-template name="replace-string">
<xsl:with-param name="text"><xsl:copy-of select="."
/></xsl:with-param>
<xsl:with-param name="from"> </xsl:with-param>
<xsl:with-param name="to"></td><td></xsl:with-param>
</xsl:call-template>
</xsl:template>
here is a replace-string function I've found
----------------------------------------------------------------------
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($text, $from)">
<xsl:variable name="before" select="substring-before($text, $from)"/>
<xsl:variable name="after" select="substring-after($text, $from)"/>
<xsl:variable name="prefix" select="concat($before, $to)"/>
<xsl:value-of select="$before"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$after"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
| |
| dbahooker@hotmail.com 2006-08-29, 6:45 pm |
| this did the trick!!
<xsl:template match="Property[@name='CHistory']">
<tr><xsl:call-template name="split" /></tr>
</xsl:template>
<xsl:template name="split">
<xsl:param name="text" select="." />
<xsl:param name="delim" select="' '" />
<xsl:choose>
<xsl:when test="contains($text,$delim)">
<td>
<xsl:value-of select="substring-before($text,$delim)" />
</td>
<xsl:call-template name="split">
<xsl:with-param name="text" select="substring-after($text,$delim)"
/>
<xsl:with-param name="delim" select="$delim" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:value-of select="$text" />
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
dbahooker@hotmail.com wrote:
> Team;
>
> I'm kindof a newbie around these parts :)
> I'm trying to replace TAB characters ( ) with </TD><TD>.. so that I
> can properly align this XML into multiple cells in a table.
>
> yes-- right now it is living as XML, tab delimited data.. and I want to
> push it into 5 different cells.
>
> here is the result: it's displaying this in IE instead of under view
> source:
> 0.1</td><td>29-Sep-2004</td><td>Draft</td><td>Dba
> Hooker</td><td>Initial Draft0
>
> under view / source; it's displaying a similiar thing but it shows up
> as HTML tags; instead of as HTML source.
>
>
> thanks SO much for your help guys!!
>
>
> here is my template call
> --------------------------------------------------------------------
> <xsl:template match="Property[@name='CHistory']">
> <xsl:call-template name="replace-string">
> <xsl:with-param name="text"><xsl:copy-of select="."
> /></xsl:with-param>
> <xsl:with-param name="from"> </xsl:with-param>
> <xsl:with-param name="to"></td><td></xsl:with-param>
> </xsl:call-template>
> </xsl:template>
>
> here is a replace-string function I've found
> ----------------------------------------------------------------------
> <xsl:template name="replace-string">
> <xsl:param name="text"/>
> <xsl:param name="from"/>
> <xsl:param name="to"/>
>
> <xsl:choose>
> <xsl:when test="contains($text, $from)">
>
> <xsl:variable name="before" select="substring-before($text, $from)"/>
> <xsl:variable name="after" select="substring-after($text, $from)"/>
> <xsl:variable name="prefix" select="concat($before, $to)"/>
>
> <xsl:value-of select="$before"/>
> <xsl:value-of select="$to"/>
> <xsl:call-template name="replace-string">
> <xsl:with-param name="text" select="$after"/>
> <xsl:with-param name="from" select="$from"/>
> <xsl:with-param name="to" select="$to"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="$text"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|