Copied to clipboard

Flag this post as spam?

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

  • Damiaan 440 posts 1295 karma points MVP 5x c-trib
    Mar 06, 2015 @ 17:44

    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

    $currentPage/ancestor-or-self::*[@level=4]/child::*[name()='DocType1' or name()='DocType2']

    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.

  • Jan Skovgaard 11264 posts 23592 karma points MVP 9x admin c-trib
    Mar 06, 2015 @ 17:53
    Jan Skovgaard

    Hi Damiaan

    I think you should be able to actually do this

    <xsl:variable name="$currentPage/ancestor-or-self::*[@level=4]/DocType1|$currentPage/ancestor-or-self::*[@level=4]/DocType2" />

    Hope this helps.


  • Sebastian Dammark 555 posts 1296 karma points
    Mar 07, 2015 @ 15:14
    Sebastian Dammark

    Or you could do something like this

    <xsl:template match="/">
        <xsl:apply-templates select="$currentPage/ancestor-or-self::*[@level=4]/*" />
    <xsl:template match="*[name()='DocType1']">
    Do stuff for Doctype 1 here
    <xsl:template match="*[name()='DocType2']">
        Do stuff for Doctype 2 here
    <xsl:template match="*" />
  • Chriztian Steinmeier 2750 posts 8456 karma points MVP 6x admin c-trib
    Mar 07, 2015 @ 17:26
    Chriztian Steinmeier

    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:

    1. The DocType2 nodes are not actually called DocType2? (XML is case-sensitive, so could be any combination, e.g. Doctype2 or docType2)
    2. The DocType2 nodes are unpublished? - The XML cache only contains published content, so no chance of getting unpublished content with XSLT
    3. The DocType2 nodes are not located at the same level as the DocType1 nodes?
    4. 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>

    (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 :-)


  • Damiaan 440 posts 1295 karma points MVP 5x c-trib
    Mar 09, 2015 @ 22:06

    I'll try it tomorrow! Thanks for all your comments!

Please Sign in or register to post replies

Write your reply to: