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 January 23rd, 2008, 03:01 PM
Authorized User
 
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default converting node to string

Consider the XML:
Code:
...
<Photo>
  <img alt="Some Image" src="/assets/image.gif" />
</Photo>
...
I'm trying to output EXACTLY the following (used inside a JavaScript). Replace the first < character to &lt; and replace every " character with \"
Code:
&lt;img alt=\"Some Image\" src=\"/assets/image.gif\" />
I am stumped on how I would even attempt this. The only way I can get the image to actually display is by using copy-of which I can't seem alter it's value in any way.

Any help is appreciated,
Steve

 
Old January 23rd, 2008, 09:35 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi,

Try something like this:

Code:
        <xsl:for-each select="//img">
            <xsl:text>&lt;</xsl:text>
            <xsl:value-of select="name()"/>
            <xsl:text> </xsl:text>
            <xsl:for-each select="@alt">
                <xsl:value-of select="name()"/>
            </xsl:for-each>
            <xsl:text>\=&quot;</xsl:text>
            <xsl:value-of select="@alt"/>
            <xsl:text>\&quot;</xsl:text>
            <xsl:for-each select="@src">
                <xsl:value-of select="name()"/>
            </xsl:for-each>
            <xsl:text>\=&quot;</xsl:text>
            <xsl:value-of select="@src"/>
            <xsl:text>\&quot;</xsl:text>
            <xsl:text>/</xsl:text>
            <xsl:text>&gt;</xsl:text>
        </xsl:for-each>
 
Old January 24th, 2008, 12:23 PM
Authorized User
 
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that is perfect - thank you! it works like a charm. the only thing i had to change was swapping the \ character and = character.
Code:
<xsl:text>\=&quot;</xsl:text> 
<xsl:text>=\&quot;</xsl:text>
thanks bonekrusher - you really saved me a lot of time and frustration.
cheers,
steve






Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting String into Node-set dved XSLT 3 January 23rd, 2008 12:40 PM
Converting a string to an expression Nick.Net VB.NET 2002/2003 Basics 1 March 5th, 2004 09:41 PM
Converting String to an integer Louisa VB.NET 2002/2003 Basics 2 March 5th, 2004 10:25 AM
Converting int to string Judex C++ Programming 3 March 1st, 2004 10:44 AM
Converting a string to a number steve456 Javascript How-To 2 November 17th, 2003 06:01 PM





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