Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2007, 07:24 AM
Authorized User
 
Join Date: Apr 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tab in XSLT in 1.0 only

Help needed to solve the following in xslt 1.0 only

Input xml
<p>
My simple \t\t text\t with\t tab
</p>

out put XML
<p>
<text>
Mysimple<tab><tab>text<tab>with<tab>tab
<text>

I need a logic to convert input to out put xml.
thanks in advance


 
Old May 8th, 2007, 07:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This kind of thing is very easy in XSLT 2.0 using xsl:analyze-string.

To do it in XSLT 1.0 you need to write a recursive template. Supply the string as a parameter to the template. If the string is empty, exit. If the first two characters are "\t", output a <tab/> element, otherwise output the first character. Then call the template recursively passing the rest of the string as the parameter value.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 8th, 2007, 07:42 AM
Authorized User
 
Join Date: Apr 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried with recursive, i don't know how to add node in recursive
can you post the complete template

 
Old May 8th, 2007, 08:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please try to write it yourself. If you can't get it to work, show us your code and I can see where you went wrong. You can't learn by asking other people to do the work.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 8th, 2007, 06:35 PM
Authorized User
 
Join Date: Apr 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

pradeepn - You can also use substring-before(). Here's a template which replaces an arbitrary string with another. You can use it as a starting point:
Code:
<xsl:template name="replace">
  <xsl:param name="string" />
  <xsl:param name="oldSub" />
  <xsl:param name="newSub" />
  <xsl:choose>
    <xsl:when test="contains($string,$oldSub)">
      <xsl:value-of select="substring-before($string, $oldSub)" />
      <xsl:value-of select="$newSub" />
      <xsl:call-template name="replace">
        <xsl:with-param name="string" select="substring-after($string, $oldSub)" />
        <xsl:with-param name="oldSub" select="$oldSub" />
        <xsl:with-param name="newSub" select="$newSub" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable a tab on a tab control. dbradley VB.NET 6 April 14th, 2011 10:04 AM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
tab control amey.agnihotri C# 2005 1 June 19th, 2007 04:10 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.