Copied to clipboard

Flag this post as spam?

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


  • Muhammad hussain 33 posts 53 karma points
    Jul 15, 2010 @ 20:58
    Muhammad hussain
    0

    Who to use Switch Statement in Xslt

    Hi


    I use Xslt and use there 4 if statement . Now My Question is that who can i use Switch Statement instead of many if else.

    Can any one Help me.

    Thanks

    Hussain

  • Kjeldsen 11 posts 25 karma points
    Jul 15, 2010 @ 21:10
    Kjeldsen
    1

    Hi Muhammad,

    XSLT has some shortcomings compared to a lot of ordinary programming language features, for example variable and switch, are not implemented the way we are typically used to from other languages. It is not a programming language in a classical sense, rather an xml parsing tool.

    I suggest that you look at "choose" at w3schools, that might be useful for you: http://www.w3schools.com/xsl/xsl_choose.asp

    Hope that helps.

     

    Brgds.

    Anders

  • Muhammad hussain 33 posts 53 karma points
    Jul 15, 2010 @ 21:15
    Muhammad hussain
    0

    Hi Anders,

    Thanks for Response. If i do Coding in C#  for Switch Statement and i want to call this Function In XSlt. WHo Can I Do this.

    The Second Thing is that i want to implement Searching from C# and use this Seaching Function in Umbraco. Who Can Do this.

    Thanks

    Hussain

     

  • Kjeldsen 11 posts 25 karma points
    Jul 15, 2010 @ 21:23
    Kjeldsen
    0

    You can develop what is known as XSLT extensions in c# and then call those from within your xslt.
    I have not done this myself, but others might be able to help you out :)

    With searching, you can create a ordinary dll and dump it in the /bin folder of the Umbraco site. From there on, you can add a usercontrol that uses the features of the dll. Or at least thats what I would do to implement my own custom search.

    I guess there are other ways to implement this as well.

    By the way with regards to switch and XSLT I would recommend sticking with your if's - even though I agree its not pretty I think its the best solution within the limitations of xslt.

    Brgds. Anders

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 21:32
    Thomas Höhler
    0

    Muhammad I think an example would help:

    Xslt with 4 if:

    <xsl:if test="CONDITION1">
    </xsl:if>
    <xsl:if test="CONDITION2">
    </xsl:if>
    <xsl:if test="CONDITION3">
    </xsl:if>
    <xsl:if test="CONDITION4">
    </xsl:if>

    Xslt with one choose instead of if:

    <xsl:choose>
    <xsl:when test="CONDITION1">
    </xsl:when>
    <xsl:when test="CONDITION2">
    </xsl:when>
    <xsl:when test="CONDITION3">
    </xsl:when>
    <xsl:when test="CONDITION4">
    </xsl:when>
    </xsl:choose>

    hth, Thomas

  • Muhammad hussain 33 posts 53 karma points
    Jul 15, 2010 @ 21:35
    Muhammad hussain
    0

    hth, Thomas,

    Thanks for Resposne but this is like if else and if else and so on. This is not like Switch in C#. The switch use case in Switch.

    Hussain

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies