Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • arviman 71 posts 92 karma points
    Aug 25, 2010 @ 21:44
    arviman
    0

    Get the value of a (value of a variable)

    What i'm trying to do here is to pass in the value of a variable as a parameter to an xsl:value-of's select attribute. (instead of just passing in a variable).

    So I have a variable dataAlias where i set the value to be passed ($currentPage/data[@alias='someproperty'])

    However, I haven't been able to figure out how actually pass in the value of $dataAlias.

    <xsl:value-of select="string($dataAlias)" disable-output-escaping="yes"/>

    The above code simply emits $currentPage/data[@alias='someproperty']. However, I would like the select attribute to work with the content of the variable and not just the variable.

    Here's the full snippet.

    Snippet

    <xsl:param name="currentPage"/>
    <xsl:param name="mostPopularProperty"/>
    <xsl:variable name="dataAlias">
      <xsl:text>$currentPage/data[@alias = '</xsl:text>$mostPopularProperty<xsl:text>']</xsl:text>
    </xsl:variable>
    <xsl:template match="/">
    
    <!--Would like to substitute string($dataAlias) with it's value
     <xsl:variable name="content">         <xsl:value-of select="string($dataAlias)" disable-output-escaping="yes"/>     </xsl:variable>

     

  • arviman 71 posts 92 karma points
    Aug 25, 2010 @ 21:47
    arviman
    0

    Sorry, for the repost, but here's the portion of the snippet( i wasn't able to edit the typo in the previous post)


    <!--Would like to substitute string($dataAlias) with the value of $dataAlias-->
     
    <xsl:variable name="content">  
          <xsl:value-of select="string($dataAlias)" disable-output-escaping="yes"/>  
      </xsl:variable>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 25, 2010 @ 21:48
    Jan Skovgaard
    0

    Hi Arviman

    I don't think you can achieve what you're trying to do by using xsl:value-of.

    However I think that the solution to your problem could maybe be to play around with entities.

    Therefore I think you should have a look at Chriztian's articles on the subject.

    http://pimpmyxslt.com/articles/entity-tricks-part1/

    http://pimpmyxslt.com/articles/entity-tricks-part2/

    I hope this helps...

    /Jan

  • arviman 71 posts 92 karma points
    Aug 25, 2010 @ 22:09
    arviman
    0

    Hi Jan,

    Thanks for the links, but I don't think it'll fit the bill here because the values I want to swap in are obtained from the parameter. From what I saw, entities are used for swapping values with literal strings.(essentially, a way to write shorthand in xslt)

    Thanks,

    Arviman

  • arviman 71 posts 92 karma points
    Aug 25, 2010 @ 22:39
    arviman
    0

    Never mind, i realized i had it right the first time around :-) The issue was with how i was reading the parameter :embarrassed:

    Here's the simple solution.

    Snippet

    <xsl:variable name="mostPopularProperty" select="/macro/mostPopularProperty"/>
    <xsl:template match="/">  
      <xsl:variable name="content">
        <xsl:value-of select="$currentPage/data [@alias=$mostPopularProperty]" disable-output-escaping="yes" />
      <xsl:variable>

     

Please Sign in or register to post replies

Write your reply to:

Draft