Copied to clipboard

Flag this post as spam?

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


  • Tim Hustler 10 posts 31 karma points
    Jan 20, 2010 @ 16:09
    Tim Hustler
    0

    <xsl:variable> with conditional select

    Hi Guys

    Can anyone tell me why this wouldn't work please?

    This works fine :

    I need to set the vaiable accoding to an XSL:CHOOSE but this XSLT won't compile for some reason?

  • Seth Niemuth 275 posts 397 karma points
    Jan 20, 2010 @ 16:43
    Seth Niemuth
    0

    I don't think you can do it like the first because the second is the syntax for when there is just one.

     

    I just did a choose with yours and this works for me...no errors:

    <xsl:variable name="eventItems"> <xsl:choose> <xsl:when test="1"> <xsl:value-of select="$matchedNodes [parent::node/@nodeName = 'Events']" /> </xsl:when> <xsl:otherwise> 1</xsl:otherwise> </xsl:choose> </xsl:variable>

  • Tim Hustler 10 posts 31 karma points
    Jan 20, 2010 @ 17:31
    Tim Hustler
    0

    Here's the full thing but it still errors for me :¬( Maybe it's my test? i've used the excat same test condition further up in the same page and that works fine, confused

    <xsl:variable name="eventItems">
    <xsl:choose>
    <xsl:when test="string(umbraco.library:RequestQueryString('tag')) = ''">
    <xsl:value-of select="$matchedNodes [parent::node/@nodeName = 'Events']"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$matchedNodes [@parentID = 1184]"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
  • Seth Niemuth 275 posts 397 karma points
    Jan 20, 2010 @ 18:02
    Seth Niemuth
    0

    Tim, 

    I just put exactly what you had into mine and it is not giving me an error/syntax error. I did put this at the top:

    <xsl:variable name="matchedNodes" select="$currentPage" />

    because I don't know what you have for $matchedNodes. I would check what is in $matchedNodes (if that is where it is giving you the error).

    You can output matchedNodes with, so that you can confirm what you want in there: <xsl:copy-of select="$matchedNodes" />

    Do you possible want this:

    $matchedNodes/parent::node[@nodeName = 'Events'] 

    seth

  • Tim Hustler 10 posts 31 karma points
    Jan 20, 2010 @ 19:14
    Tim Hustler
    0

    I'm not sure what the bug is to be honest

    I'm amending the XSLTSearch package to use my tagging system so the matchedNodes variable either collects from the regular search items or from tagsLib:getContentsWithTags($search) in the case of a tagged search

    Further splitting then occurs so i need to be able to select, from $matchedNodes, the Events within that list as these are displayed in a different section

    I just thought it was a syntax error because i've used this conditional method of populating XSLT variables elsewhere in the file

    It's really odd though.  If i hard-code it foir the search i'm performing I get results if i set it using

    <xsl:variable name="eventItems" select="$matchedNodes/parent::node [@nodeName = 'Events']" />

    Or

    <xsl:variable name="eventItems" select="$matchedNodes [@parentID = 1184]" />

    but not conditionally, which is waht i need to do as the user could perform both types of search to the same page

    Is there anything else i should be checking?

  • Tim Hustler 10 posts 31 karma points
    Jan 20, 2010 @ 19:18
    Tim Hustler
    0

    just to add, i'm setting this up in visual studio and it doesn't complain. when i view the marco within umbraco it won't save and the front-end page just gives me Error parsing XSLT file: \xslt\XSLTsearch.xslt

    The stacktrace from within umbraoc isn;t very informative either

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 items)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    Thanks for taking the time to look into this for me Seth, i'm really stumped and this is one of my final hurdles for this deployment

  • Seth Niemuth 275 posts 397 karma points
    Jan 20, 2010 @ 19:41
    Seth Niemuth
    0

    If you know that both of these work:

    <xsl:variable name="eventItems" select="$matchedNodes [@parentID = 1184]" />
    <xsl:variable name="eventItems" select="$matchedNodes/parent::node [@nodeName = 'Events']" />

    then, it will be something to do your test statement (<xsl:when test="string(umbraco.library:RequestQueryString('tag')) = ''">)

    Since XSLT is so hard to debug, with I end up making really small changes. So, for example, just put:

    <xsl:when test="1">

    <xsl:variable name="eventItems" select="$matchedNodes [@parentID = 1184]" />
    </when>

    to confirm that it is your test statement that is giving the error. If it is still giving an error, back up another step, until you can pinpoint where the problem is originating.

  • Tim Hustler 10 posts 31 karma points
    Jan 20, 2010 @ 22:21
    Tim Hustler
    0

    Aye, i will step through it again in the morning

    The thing is, i use that test, albeit in reverse (!= as opposed to = in this instance) and it wortks fine.  Maybe i'll try the reverse and see what happens.  Sometime it's best to walk away as you'll often see the answer in the morning

    Thanks for all your help Seth, always good to have another pair of eyes :¬)

    cheers

    Tim

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jan 20, 2010 @ 22:42
    Chriztian Steinmeier
    0

    Hi Tim,

    There's a difference between setting a variable using the select attribute, and using the contents (like you do when you use choose et al.)

    Using select, the variable kinda points directly to (frequently) a node or a node-set, but using value-of inside of the variable, sets the variable to the text value of the node(s) referenced - e.g.:

    <xsl:variable name="news" select="node[@nodeTypeAlias = 'NewsItem']" />
    

    Not the same as:

    <xsl:variable name="news">
        <xsl:value-of select="node[@nodeTypeAlias = 'NewsItem']" />
    </xsl:variable>

    You can however use copy-of instead, to get the nodes, but there's a gotcha with that, that means you can't access the nodes in the variable unless you use the node-set() extension function available as either msxml:node-set() or Exslt.ExsltCommon:node-set() (methinks...):

    <xsl:variable name="news">
        <xsl:copy-of select="node[@nodeTypeAlias = 'NewsItem']" />
    </xsl:variable>
    <xsl:for-each select="msxml:node-set($news)/node">
       ...
    </xsl:for-each>

    /Chriztian

  • Tim Hustler 10 posts 31 karma points
    Jan 21, 2010 @ 10:31
    Tim Hustler
    0

    I still couldn't set the variable conditionally using copy-of.  good point though Chriztian, makes total sense when I think about it

    if i could get this to work i would be laughing

          <xsl:variable name="eventItems">
             
    <xsl:choose>
                 
    <xsl:when test="string(umbraco.library:RequestQueryString('tag')) = ''">
                     
    <xsl:copy-of select="$matchedNodes [parent::node/@nodeName = 'Events']"/>
                 
    </xsl:when>
                 
    <xsl:otherwise>
                     
    <xsl:copy-of select="$matchedNodes [@parentID = 1184]"/>
                 
    </xsl:otherwise>
             
    </xsl:choose>
         
    </xsl:variable>

    As a workaround, i have created a copy of the template and i call the one i need depending on the type of search i am doing at the time.  Dirty i think, but the template was complete before i added the tagging functionality and it looks like it should. 

    Is there another way to do that tagLib search maybe? The issue really stems for the fact that tagLib returns it's results as raw nodes with no parents, wheras the regular XSLTSearch method gives the whole tree so you can traverse it as normal.

    Thanks for all your pointers though guys, glad you were able to offer me some advice :¬)

  • mummmybot 3 posts 23 karma points
    May 13, 2010 @ 20:26
    mummmybot
    0

    I have been having a similar problem. The only solution I have so far is to set the variable to the node Id string, and then everytime the node is needed run umbraco.library:GetXmlNodeById($yourVariableId). Not pretty, but it is a dynamic variable with which you can set a node.

    Declare variable:

    <xsl:variable name="rootNode">
        <xsl:choose>
            <xsl:when test="/macro/rootNode != ''">
                <xsl:value-of select="/macro/rootNode"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$currentPage/@id"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    And call variable:

    <xsl:value-of select="umbraco.library:GetXmlNodeById($rootNode)/data [@alias = 'yourAlias']"/>
Please Sign in or register to post replies

Write your reply to:

Draft