Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / August 2006



Tip: Looking for answers? Try searching our database.

newbie xsl / xslt question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dbahooker@hotmail.com - 28 Aug 2006 23:34 GMT
Team;

I'm kindof a newbie around these parts :)
I'm trying to replace TAB characters (&#09;) 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">&#09;</xsl:with-param>
        <xsl:with-param name="to">&lt;&#47;td&gt;&lt;td&gt;</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 - 29 Aug 2006 17:43 GMT
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="'&#x09;'" />

        <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>

> Team;
>
[quoted text clipped - 53 lines]
>     </xsl:choose>            
>  </xsl:template>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.