Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Jul 30, 2010 @ 08:17
    Kasper Dyrvig
    0

    Shouldn't this be working?

    I'm trying to get a xml-node by its name... I have made this:

    <xsl:choose>
     <xsl:when test="string(umbraco.library:RequestQueryString('txt')) != ''">
       <xsl:variable name="qs" select="umbraco.library:RequestQueryString('txt')" />
       <xsl:for-each select="$currentPage/ancestor-or-self::root//node [@nodeTypeAlias='Area']">
         <xsl:choose>
           <xsl:when test="ancestor-or-self::node [@nodeTypeAlias = 'Area']/@nodeName = $qs">
      <xsl:variable name="node" select="ancestor-or-self::node [@nodeTypeAlias = 'Area']/@nodeName = $qs" />

    <h4><xsl:value-of select="$node/name" />:</h4>

    </xsl:when>
    <xsl:otherwise>
      <h2>oops...</h2>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
    <h2>oops... again</h2>
    </xsl:otherwise>
    </xsl:choose>

     

    What I get is nothing, not even an error message or my "oopses"!?! Can someone help me out here? Thank you

  • Sascha Wolter 615 posts 1101 karma points
    Jul 30, 2010 @ 11:35
    Sascha Wolter
    0

    Hiya,

    If I understand this correctly you want to loop through all nodes with type 'Area' that are scattered throughout your site and print out the node name in <h4> tags if it matches the querystring. Try changing

    <xsl:when test="ancestor-or-self::node [@nodeTypeAlias = 'Area']/@nodeName = $qs">
      <xsl:variable name="node" select="ancestor-or-self::node [@nodeTypeAlias = 'Area']/@nodeName = $qs" />

    to

    <xsl:when test="current()/@nodeName = $qs">
      <xsl:variable name="node" select="current()/@nodeName = $qs]" />

    [this is the legacy XML schema, so won't work in 4.5 I guess]

    The reason for this is that you are already looping through all the nodes with @nodeTypeAlias='Area', so you just need to see if the current item in the loop, which is explicitly accessible via current(), fulfills your requirements. You can also just omit the current()/ part as the default is to use the current item in the 'loop'.

    Sascha


  • Kasper Dyrvig 246 posts 379 karma points
    Aug 09, 2010 @ 09:32
    Kasper Dyrvig
    0

    Hi Sascha,

    I would guess that your solution is correct - it seams logical - but I think your right about it won't work in 4.5... 

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 10, 2010 @ 10:40
    Kasper Dyrvig
    0

    I now have the 4.5.1 version of umbraco, but still no result. Do any one have other ideas? Appreciate

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 10, 2010 @ 10:58
    Chriztian Steinmeier
    0

    Hi Webspas,

    In XSLT you just ask for the stuff you want - no need to iterate/loop through everything and query all the nodes for something. That's built into the language:

    <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />
    <xsl:variable name="qs" select="umbraco.library:RequestQueryString('txt')" />
    
    <xsl:template match="/">
        <xsl:if test="normalize-space($qs)">
            <!-- Works in 4.0 -->
            <xsl:apply-templates select="$root//*[@nodeTypeAlias = 'Area'][@nodeName = $qs]" />
    
            <!-- Works in 4.5 -->
            <xsl:apply-templates select="$root//Area[@nodeName = $qs]" />
        </xsl:if>
    </xsl:template>
    
    <!-- Template for output of the selected node(s) -->
    <xsl:template match="*[@isDoc] | node">
        <h4>
            <xsl:value-of select="@nodeName" />
        </h4>
    </xsl:template>
    

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 10, 2010 @ 14:17
    Kasper Dyrvig
    0

    Wohoo!!! It works! Thank you very much Chriztian!

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 13, 2010 @ 09:27
    Kasper Dyrvig
    0

    I'm sorry to take this up again, but I needed to change the field that umbraco is searching for... instead of searching by the nodename, it has to search by a field called roomID. That is a field that contains an ID from a database.

    I have changed the code Chriztian to this, but that gives me nothing.

    <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />
    <xsl:variable name="qs" select="umbraco.library:RequestQueryString('id')" />
        
    <xsl:template match="/">
      <xsl:if test="normalize-space($qs)">
        <xsl:apply-templates select="$root//Stay[rotelID = $qs]" />
      </xsl:if>
    </xsl:template>

    <xsl:template match="*[@isDoc] | node"></xsl:template>

     

    I really hope you can help me out here! Thank you.

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 13, 2010 @ 09:32
    Kasper Dyrvig
    0

    No, sorry! Everything is in order. Thank enyway

Please Sign in or register to post replies

Write your reply to:

Draft