Copied to clipboard

Flag this post as spam?

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


  • ryan j 3 posts 23 karma points
    Mar 19, 2012 @ 16:11
    ryan j
    0

    Macro parameters - unable to use in XSLT variable?

    I'm trying to pass a field value into aa variable in an XSLT however it's not working how i'd expected.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
    xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
    xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
    xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="xmlHost" select="'http://some_url/'"/>
    <xsl:param name="xmlAccount" select="/macro/account"/>
    <xsl:param name="xmlQuery" select="umbraco.library:RequestServerVariables('QUERY_STRING')"/>

    <xsl:template match="/">

    <xsl:variable name="test">some_value</xsl:variable>
    <xsl:variable name="test2"><xsl:value-of select="$xmlAccount"/></xsl:variable>
    <xsl:variable name="searchURL" select="concat($xmlHost, '?Account=', $test, '&amp;', $xmlQuery)"/>

    <textarea>
    <xsl:value-of select="$test"/>
    <xsl:value-of select="$test2"/>
    </textarea>

    </xsl:template>

    </xsl:stylesheet>

    This is a stripped down version of my code, but essentially whilst $test and $test2 render properly in the textarea, so i know the macro param value is being passed though into the xslt, if i try to use the variable pulled from the macro in $searchURL it doesn't even save properly.

    I doubt i'm the first person to run into this, but my googling has been fruitless, anybody got any thoughts on how i can make this work?

    cheers

     

  • ryan j 3 posts 23 karma points
    Mar 19, 2012 @ 16:17
    ryan j
    0

    for what it's worth, directly pointing to $xmlAccount in the variable and using <xsl:variable name="test2"select="$xmlAccount"/> don't work either.

  • ryan j 3 posts 23 karma points
    Mar 19, 2012 @ 17:05
    ryan j
    0

    okay, weirdness ensues. i can get it working now, but only if i force the save not to check for errors.

    the resulting page renders fine, the xml is well-formed, nothing has exploded yet so i'm kinda assuming the web interface's error checker is doing something crazy.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 19, 2012 @ 23:01
    Chriztian Steinmeier
    0

    Hi ryan,

    Actually, that's exactly what's going on - when you save the file, Umbraco will perform a transformation with it - just to see if it's a valid XML file etc. - but that transformation won't have a useful $currentPage assigned, neither will it have values in the macro parameters (which values should it use?)

    So usually you'd do some kind of safe-guarding to make sure there's a value in the variable before you use it - a la this:

    <xsl:param name="xmlHost" select="'http://some_url/'"/>
    <xsl:param name="xmlAccount" select="/macro/account"/>
    <xsl:param name="xmlQuery" select="umbraco.library:RequestServerVariables('QUERY_STRING')"/>
    
    <xsl:template match="/">  
    
        <xsl:if test="$xmlAccount">
            <xsl:variable name="test">some_value</xsl:variable>
            <xsl:variable name="test2"><xsl:value-of select="$xmlAccount"/></xsl:variable>
            <xsl:variable name="searchURL" select="concat($xmlHost, '?Account=', $test, '&amp;', $xmlQuery)"/>     
    
            <textarea>
                <xsl:value-of select="$test"/>
                <xsl:value-of select="$test2"/>
            </textarea>
        </xsl:if>
    
    </xsl:template>

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft