I'm feeling really dumb right now. I can loop through all of the children based on the type, but can't figure out how to do it based on the current item.
I want to check if the current node's name is NewsItem. If it is....display one template, otherwise do a different template.
Now that I look at it, I should just check the NodeType, but I've spent so much time trying to figure this out....that I just want to know the answer now.
Hi Chad, Please could you give an example of the context (e.g. XSLT) where you're trying? E.g., you could use the name() function in XPath, or apply a template matching the node name
Now just out of curiosity, is there a way to retrieve the name if you don't know it? Say I was trying to compare two nodes to each other (I know I can use the nodetype id number, but I'm trying to get how this XSLT works.
Ie. You can't just type $currentNode/name(); That error's out. Basically what I'm trying to do is this:
<xsl:when test="$currentNode[name()] = $itemTemplate"> 1<xsl:apply-templates select="$currentNode" mode="single" /> </xsl:when> <!-- Current Item is a Container for News Items --> <xsl:otherwise>
</xsl:otherwise>
Yet the if statement that works, can't be used in this context since you need to be able to pull the value to compare it to the variable $itemTemplate. Again, the smart thing to do at this point is change how $itemTemplate works and change it to $itemTemplateId and boom...this would be done and easy. But how would I ever learn if I always did the easy thing? Right?
(The extra spaces aren't necessary - just there to clarify the need for the apostrophes which are required.)
This is easily confused when ping-pong'ing between self::NewsItem (where you're NOT using a string) and testing the result of name() (where you ARE using a string).
Get current node's type in 4.5 schema
I'm feeling really dumb right now. I can loop through all of the children based on the type, but can't figure out how to do it based on the current item.
The XML for my current item is:
I want to check if the current node's name is NewsItem. If it is....display one template, otherwise do a different template.
Now that I look at it, I should just check the NodeType, but I've spent so much time trying to figure this out....that I just want to know the answer now.
Any help is appreciated.
Hi Chad, Please could you give an example of the context (e.g. XSLT) where you're trying? E.g., you could use the name() function in XPath, or apply a template matching the node name
Chad,
Try the following:
--Chris
Hi Chad,
You can either do what Chris suggests, or you can use test the self:: axis, like this:
(My personal belief is that an axis check performs better than a call to name(), but that's probably of no real concern to anybody :-)
/Chriztian
while this did not:
Now just out of curiosity, is there a way to retrieve the name if you don't know it? Say I was trying to compare two nodes to each other (I know I can use the nodetype id number, but I'm trying to get how this XSLT works.
Ie. You can't just type $currentNode/name(); That error's out. Basically what I'm trying to do is this:
<xsl:when test="$currentNode[name()] = $itemTemplate">
1<xsl:apply-templates select="$currentNode" mode="single" />
</xsl:when>
<!-- Current Item is a Container for News Items -->
<xsl:otherwise>
</xsl:otherwise>
Yet the if statement that works, can't be used in this context since you need to be able to pull the value to compare it to the variable $itemTemplate. Again, the smart thing to do at this point is change how $itemTemplate works and change it to $itemTemplateId and boom...this would be done and easy. But how would I ever learn if I always did the easy thing? Right?
Thanks for the answers so far.
-C
Hi again,
You can use name() like that - you just need to do it right :-)
/Chriztian
I just tried it and I get an XSLT error. Just says 'false'.
-C
Okay - how do you set $currentNode ?
/Chriztian
<xsl:choose>
<xsl:when test="$startingNode != ''">
<xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById($startingNode )"></xsl:variable>
<xsl:call-template name="mainFunctionality">
<xsl:with-param name="currentNode" select="$currentNode" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="currentNode" select="$currentPage"></xsl:variable>
<xsl:call-template name="mainFunctionality">
<xsl:with-param name="currentNode" select="$currentNode" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
Hi Chad,
OK - just to be sure - how do you set $itemTemplate? I'm guessing something like this:
(The extra spaces aren't necessary - just there to clarify the need for the apostrophes which are required.)
This is easily confused when ping-pong'ing between self::NewsItem (where you're NOT using a string) and testing the result of name() (where you ARE using a string).
/Chriztian
Ok. It's working today.
Thanks for all of your help!
-C
is working on a reply...