Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Apr 02, 2013 @ 12:47
    Bo Damgaard Mortensen
    0

    Getting XML elements from a commaseparated string of ids

    Hi all,

    I have some trouble figuring this one out in XSLT :-)

    I have an XML structure that looks like this:

    <members>
         <member id="1"> ... </member>
         <member id="2"> ... </member>
         <member id="3"> ... </member>
    </member>

    And then I have a string of commaseaparted ids:

    "2, 3, 5, 1"

    Is there any way to get the corresponding <member> XML elements from the ids in the string? :-)

    Thanks a lot in advance,

    Bo

  • Sebastian Dammark 583 posts 1407 karma points
    Apr 02, 2013 @ 12:52
    Sebastian Dammark
    0

    Hi Bo

    Couldn't you use the umbraco:library.split() function for this job ?

    // Dammark

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Apr 02, 2013 @ 12:56
    Bo Damgaard Mortensen
    0

    Hi Sebastian,

    Thanks for your input :-) Appreciated!

    I don't think I was very clear in my original post (sorry about that). I have two variables: one with the <members><member.. </members> XML and one with a commaseparated string containing random member ids. So what I need to do, is to find the <member> elements which matches the ids in my string variable :-)

    Let me know if it dosn't make sense ;-)

    Thanks again!

    - Bo

  • Sebastian Dammark 583 posts 1407 karma points
    Apr 02, 2013 @ 13:08
    Sebastian Dammark
    1

    code

    <xsl:variable name="members" />
    <xsl:variable name="memberIds" value="'1, 2, 3, 4, 5'" />
    <xsl:variable name="splitMemberIds" value="umbraco:library.Split($memberIds, ', ')" />

    <xsl:apply-template select="$splitMemberIds/descendant::value[normalize-space()]" />

    <xsl:template match="value">
    <xsl:apply-template select="$members/descendant::member[@id = .]" />
    </xsl:template>

    <xsl:template match="member">
    // Do what ever you like here ...
    </xsl:template> 

    I haven't tested the code above ... so there might be typos and so on.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Apr 02, 2013 @ 13:38
    Bo Damgaard Mortensen
    0

    h5yr, Sebastian! :-) That worked just as it should.

    Thanks a lot for your help !

    - Bo

Please Sign in or register to post replies

Write your reply to:

Draft