Copied to clipboard

Flag this post as spam?

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


  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 15:55
    Bob Jones
    0

    Help with converting old schema tags Xslt

    I am trying to convert the neat example for filtering by tag selection as featured in one of Tim's datatype video tutorials, here is his code:

    <ul>

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1'

    and (umbraco.library:Request('tag') = '' or contains(data [@alias = 'tags'],umbraco.library:Request('tag')))]">

    <li>

    <a href="{umbraco.library:NiceUrl(@id)}">

    <xsl:value-of select="@nodeName"/>

    </a>

    </li>

    </xsl:for-each>

    </ul>

    I am struggling to convert this to the latest xsl schema, this is what I have tried: 

    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1'
      and (umbraco.library:Request('tag') = '' or contains(@tags,umbraco.library:Request('tag')))]">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>

    The xslt  will save without any errors but if I set a tag in the filter the page returns blank.

     

    Can someone help me with the correct code for this example. Thanks for links to other pages that feature the latest xslt code but I am still struggling in some places to convert from the old schema..

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 21, 2011 @ 16:04
    Chriztian Steinmeier
    2

    Hi Bob,

    This should take care of the filtering - even the case of no tag in QueryString (not tested, though):

    <ul>
        <xsl:variable name="reqTag" select="umbraco.library:Request('tag')" />
    
        <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)][contains(tags, $reqTag)]">
            <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                </a>
            </li>
        </xsl:for-each>
    </ul>

    Always, always, always create a temp variable for stuff that makes your XPath impossible to read (and error-prone to change). 

    /Chriztian

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 16:11
    Bob Jones
    0

    Thanks Chriztian will give that a try. Yeh I had a nagging feeling that I should be using a variable but was perhaps following the tutorial code too closely, takes a while for the penny to drop when I start learning new languages!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 21, 2011 @ 16:13
    Jeroen Breuer
    0

    You can try the XsltUpdater package. Perhaps your code is already fine after that.

    Jeroen

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 18:11
    Bob Jones
    1

    Thank you Chriztian that code worked perfectly! And thanks Jeroen for the link that looks as though it could be very useful for me working with some of the older code samples from the video tutorials

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 22, 2011 @ 11:56
    Jan Skovgaard
    0

    There is also the online converter tool made by Tommy Poulsen here: http://blackpoint.dk/umbraco-workbench/tools/convert-xml-schema-to-45-.aspx?p=2

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft