XSL replace value with string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • go4gator
    New Member
    • Jul 2008
    • 1

    XSL replace value with string

    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=xml]
    <xsl:for-each select="value">
    <xsl:if test="value &amp;lt;= 5.00">
    <xsl:value-of select="Free" />"
    </xsl:if>
    </xsl:for-each>
    [/code]
    Last edited by jkmyoung; Jul 14 '08, 10:02 PM. Reason: code tags
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    [code=xml]
    <xsl:if test=". &amp;lt;= 5.00">
    [/code]

    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=xml]
    <value>
    <value>5.00</value>
    </value>
    [/code]

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      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=xml]
      <xsl:for-each select="books/book">
      <xsl:if test="value &lt;= 5.00">
      <xsl:value-of select='free'/>
      </xsl:if>
      </xsl:for-each>
      <xsl:for-each select="books/book">
      <xsl:sort select="edition " order="descendi ng" />
      <tr>
      <td><xsl:valu e-of select="title"/></td>
      <td><xsl:valu e-of select="rating"/></td>
      <td><xsl:valu e-of select="author"/></td>
      <td><xsl:valu e-of select="publish er"/></td>
      <td><xsl:valu e-of select="conditi on"/></td>
      <td><xsl:valu e-of select="binding "/></td>
      <td><xsl:valu e-of select="value"/></td>
      <td><xsl:valu e-of select="edition "/></td>
      </tr>

      </xsl:for-each>
      [/code]
      Thanks again

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        <xsl:value-of select="'free'"/>

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

        Comment

        Working...