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
[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'.
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>
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.
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
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
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...
I now have the 4.5.1 version of umbraco, but still no result. Do any one have other ideas? Appreciate
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:
/Chriztian
Wohoo!!! It works! Thank you very much Chriztian!
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.
No, sorry! Everything is in order. Thank enyway
is working on a reply...