Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

XSL replace value with string

Question posted by: go4gator (Newbie) on July 14th, 2008 02:12 PM
I'm a newbie, and I have an XML data file with Book data. I'm trying to replace a value with a string. Specifically trying to test for "if value is less than 5.00 than replace value with the string "Free". Here is what is not working but I receive no errors.
Code: ( text )
  1. <xsl:for-each select="value">
  2.       <xsl:if test="value &lt;= 5.00">
  3.       <xsl:value-of select="Free" />"
  4.       </xsl:if>
  5.     </xsl:for-each>
Last edited by jkmyoung : July 14th, 2008 at 10:02 PM. Reason: code tags
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
jkmyoung's Avatar
jkmyoung
Moderator
765 Posts
July 14th, 2008
10:01 PM
#2

Re: XSL replace value with string
Code: ( text )
  1. <xsl:if test=". &lt;= 5.00">


Once you do the for-each, you're already in the value node. Your current code looks for a value node inside the value node! eg like:

Code: ( text )
  1. <value>
  2.   <value>5.00</value>
  3. </value>

Reply
jkmyoung's Avatar
jkmyoung
Moderator
765 Posts
July 15th, 2008
02:38 PM
#3

Re: XSL replace value with string
From go4gator
--------------------------------------------------------------------------------

It still doesn't work. Maybe more code will give you more insight. I think I may need to declare the string "Free" somehow. Got any ideas? The second sort works fine.
I changed the code to:

Code: ( text )
  1. <xsl:for-each select="books/book">
  2. <xsl:if test="value <= 5.00">
  3. <xsl:value-of select='free'/>
  4. </xsl:if>
  5. </xsl:for-each>
  6. <xsl:for-each select="books/book">
  7. <xsl:sort select="edition" order="descending" />
  8. <tr>
  9. <td><xsl:value-of select="title"/></td>
  10. <td><xsl:value-of select="rating"/></td>
  11. <td><xsl:value-of select="author"/></td>
  12. <td><xsl:value-of select="publisher"/></td>
  13. <td><xsl:value-of select="condition"/></td>
  14. <td><xsl:value-of select="binding"/></td>
  15. <td><xsl:value-of select="value"/></td>
  16. <td><xsl:value-of select="edition"/></td>
  17. </tr>
  18.  
  19. </xsl:for-each>

Thanks again

Reply
jkmyoung's Avatar
jkmyoung
Moderator
765 Posts
July 15th, 2008
02:39 PM
#4

Re: XSL replace value with string
<xsl:value-of select="'free'"/>

Use single quotes inside the double quotes to declare 'free' as a string.

Reply
Reply
Not the answer you were looking for? Post your question . . .
180,802 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top XML Forum Contributors