<xsl:template match="/">
<xsl:apply-templates select="$currentPage/ancestor-or-self::*[@level=4]/*" />
</xsl:template>
<xsl:template match="*[name()='DocType1']">
Do stuff for Doctype 1 here
</xsl:template>
<xsl:template match="*[name()='DocType2']">
Do stuff for Doctype 2 here
</xsl:template>
<xsl:template match="*" />
What you're doing is technically correct - you can shorten the XPath by doing a couple of things, but as it is, it should do exactly what you want; so if you're only getting DocType1 nodes in the result, here's why:
The DocType2 nodes are not actually called DocType2? (XML is case-sensitive, so could be any combination, e.g. Doctype2 or docType2)
The DocType2 nodes are unpublished? - The XML cache only contains published content, so no chance of getting unpublished content with XSLT
The DocType2 nodes are not located at the same level as the DocType1 nodes?
In your specific case: Pure Magic? :-)
Okay - so far so good; there's another thing that could trip you up: Let's say you've selected the nodes and put them in a variable, and you just want to test whether you got the nodes or not, so you try this:
<xsl:value-of select="$nodes" />
...thinking that you should get some sort of combined output, right? Wrong - value-of will print the string-result of a single node, but you're feeding it a set of nodes, so it'll print the string() version of the first node in the set. If that's a DocType1 node, you'll see that and think "where's my DocType2 node?"
So if you're testing, you'd better use count() to make sure, e.g.:
<xsl:value-of select="count($nodes)" />
...and you'd see whether you had only a single node or you'd actually managed to select more than one.
Even better though, as Sebastian was hinting at, use match templates to verify the result, e.g.:
<xsl:apply-templates select="$nodes" />
<xsl:template match="*[@isDoc]">
<p>My name is <xsl:value-of select="name()" /></p>
</xsl:template>
(Using a generic template will catch the case where you've accidentally camelCased the name - using exact matches would trip those results up)
Hope you have enough tools for debugging this now :-)
Get 2 different document types using xpath
I need to filter out 2 document types on an xpath-based datatype.
But if i change this to
I still only get only docType1 childs. What am I doing wrong?
I don't think it matters, but it's an old umbraco 4.10.11.
Hi Damiaan
I think you should be able to actually do this
Hope this helps.
/Jan
Or you could do something like this
Hi Damiaan,
What you're doing is technically correct - you can shorten the XPath by doing a couple of things, but as it is, it should do exactly what you want; so if you're only getting DocType1 nodes in the result, here's why:
Okay - so far so good; there's another thing that could trip you up: Let's say you've selected the nodes and put them in a variable, and you just want to test whether you got the nodes or not, so you try this:
...thinking that you should get some sort of combined output, right? Wrong - value-of will print the string-result of a single node, but you're feeding it a set of nodes, so it'll print the string() version of the first node in the set. If that's a DocType1 node, you'll see that and think "where's my DocType2 node?"
So if you're testing, you'd better use count() to make sure, e.g.:
...and you'd see whether you had only a single node or you'd actually managed to select more than one.
Even better though, as Sebastian was hinting at, use match templates to verify the result, e.g.:
(Using a generic template will catch the case where you've accidentally camelCased the name - using exact matches would trip those results up)
Hope you have enough tools for debugging this now :-)
/Chriztian
I'll try it tomorrow! Thanks for all your comments!
is working on a reply...