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?
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.
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:
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...
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?
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:
/Chriztian
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.
is working on a reply...