Copied to clipboard

Flag this post as spam?

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


  • philw 99 posts 434 karma points
    Apr 20, 2013 @ 11:44
    philw
    0

    Select node by parametrized attribute

    Background: I have a bunch of site-wide constants which I want to be defined on my site-root (home page) so content editors can change them there. I want those same content editors to be able to insert the constants (things like telephone number), in any content page.

    I have the basic structure, and I have an XSLT file which takes a parameter. I can pull out the values if I explicitly code them in the XSLT, like this, which works fine:

      <!-- Get the page with the values in it -->
      <xsl:param name="homePage" select="$currentPage/ancestor-or-self::*[@level=1]"/>   
      <!-- Return specific value -->
      <xsl:value-of select="$homePage/obfuscatedEmailAddress"/> 

    However I want the content editor to be able to use the same macro for all the constants, just providing the name of each constant. So for example "telephoneNumber" will return that, where as "emailAddress" will return that. This way I can ensure the values are all consistent and easily changable.

    I have added therefore a macro parameter, which I can verify is arriving correctly at the XSLT. However...

     

      <xsl:param name="fieldName" select="/macro/fieldName"/>
    
      <xsl:param name="homePage" select="$currentPage/ancestor-or-self::*[@level=1]"/>   
    
      <!-- Return PARAMETERIZED value: none of these or anything like them works -->
      <xsl:value-of select="$homePage/$fieldName"/> 
      <xsl:value-of select="$homePage/data [@alias=$fieldName]"/> 

    In short, I need to be able to construct the "select" statement so that the select picks the data attribute with the passed-in name. So the one piece of XLST will be used to pull any "data" value by alias from that root page.

    I'm sure this is basic stuff, but a lot of googling hasn't turned up the answer for me yet. Any ideas?

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Apr 20, 2013 @ 20:29
    Chriztian Steinmeier
    1

    Hi philw,

    You were pretty close, actually :-)

    The latter would work if you were using the "Legacy Schema" (Umbraco versions 4.1 and below). Here's the one you need:

    <xsl:value-of select="$homePage/*[name() = $fieldName]" />

     

    /Chriztian

  • philw 99 posts 434 karma points
    Apr 20, 2013 @ 23:35
    philw
    0

    Brilliant! I'd got as far as "$homePage [@*[name()='alias']", but I had not managed to get anything that worked, but this worked first time - thanks, now I can move forward.

Please Sign in or register to post replies

Write your reply to:

Draft