CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Posts
    3

    replacing string

    I have a xml file like this.

    <projectteam>
    <projectname>The Killer Application {a href="http://www.hotmail.com"}hotmail.com{/a}</projectname>
    </projectteam>

    but i want to convert '}' to '>' and '{' to '<' with xsl this function.
    <xsl:template name="string-replace" >
    <xslaram name="string"/>
    <xslaram name="from"/>
    <xslaram name="to"/>
    <xsl:choose>
    <xsl:when test="contains($string,$from)">
    <xsl:value-of select="substring-before($string,$from)"/>
    <xsl:value-of select="$to"/>
    <xsl:call-template name="string-replace">
    <xsl:with-param name="string" select="substring-after($string,$from)"/>
    <xsl:with-param name="from" select="$from"/>
    <xsl:with-param name="to" select="$to"/>
    </xsl:call-template>
    </xsl:when>
    <xsltherwise>
    <xsl:value-of select="$string" disable-output-escaping="yes"/>
    </xsltherwise>
    </xsl:choose>
    </xsl:template>


    cuz i might have to generate html and other format. but when i try like this, it converts only '>' to a&gt; which is html tag. but i want '<'. is there any way to do this? please help...

  2. #2
    Join Date
    May 2003
    Location
    Denmark
    Posts
    1,315
    You can never output a lone < or > character in an xml file. You could set the output content type to text, in which case you should get the result you want. But this is a bad idear if you are using the stylesheet in an application that expects xml/html output.

    But you are really, looking at this the wrong way, trying to produce html elements by outputting their string encoding. Thats not the way to go.

    What you should do is create the anchor using an xsl:element, something like this.
    Code:
    <xsl:element name="a">
      <xsl:attribute name="href">
         <xsl:text>www.w3c.org</xsl:text>
      </xsl:attribute>
      <xsl:text>w3c</xsl:text>
    </xsl:element>
    Last edited by khp; February 1st, 2004 at 09:12 PM.
    The biggest problem encountered while trying to design a system that was completely foolproof,
    was, that people tended to underestimate the ingenuity of complete fools.
    Douglas Adams

  3. #3
    Join Date
    Feb 2004
    Posts
    3
    I understand that you are saying. but i have to generate it for html and other format(XSL-FO)that generates PDF.

    The problem is that i don't know where the anchor tag is going to be embedded in xml. it comes from a database table. that's why i want to replace '{' with '<' something like this.

    is there another solution?

  4. #4
    Join Date
    May 2003
    Location
    Denmark
    Posts
    1,315
    Originally posted by caesarkim
    I understand that you are saying. but i have to generate it for html and other format(XSL-FO)that generates PDF.
    That makes no difference.

    Originally posted by caesarkim
    The problem is that i don't know where the anchor tag is going to be embedded in xml. it comes from a database table.
    If you know where to put the < character you must also know where to put the element.

    Originally posted by caesarkim
    that's why i want to replace '{' with '<' something like this.
    You are still looking at it the wrong way.

    Originally posted by caesarkim
    is there another solution?
    No.
    The biggest problem encountered while trying to design a system that was completely foolproof,
    was, that people tended to underestimate the ingenuity of complete fools.
    Douglas Adams

  5. #5
    Join Date
    Feb 2004
    Posts
    3
    i don't know where the '<' is going to show up...

  6. #6
    Join Date
    May 2003
    Location
    Denmark
    Posts
    1,315
    Yes you do, otherwise you would not be able to put anything there.
    The biggest problem encountered while trying to design a system that was completely foolproof,
    was, that people tended to underestimate the ingenuity of complete fools.
    Douglas Adams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured