Copied to clipboard

Flag this post as spam?

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


  • Alec Colebrook-Clark 134 posts 258 karma points
    Sep 07, 2009 @ 16:47
    Alec Colebrook-Clark
    0

    XSLT string manipulation

    Howdy All,

    I have just used umb import to impornt (surprise surprise) a bibliography database into umbraco. This however is a problem as the database is incredibley inconsistent. This has lead to my current problem of trying to sort the nodes using <xsl:sort>. Im sorting cronologically by a field named date. However during the import and the state of the database i have some fields that conatain records like "2009may" or "2007 - 2009".

    This proves a problem when sorting as these arent in the correct chronological positon that they should be in. Also I am wanting to break it up in sections (blocks of 10 years) which is also poses a problem due to said database. i have tried a substring query/text to take the first 4 characters (the year) and test it against a static value (e.g 1930). I have failed. Is there anyway i can split the field up to only take the year value and test that to make my categories or will i have to re-import that database?

    my xsl is as follows

     


    <xsl:template match="/">



    <xsl:for-each select="$currentPage/node[string(data[@alias='umbracoNaviHide']) != '1']">
    <xsl:sort select="./data[@alias = 'bibYear']" data-type="number" order="descending" />
    <xsl:if test="substring(./data,0,'4') &lt; '1930'">
    <xsl:value-of select="@nodeName"/> &nbsp; <xsl:value-of select="./data [@alias = 'bibYear']" />
    </xsl:if>


    <xsl:if test="$currentPage/node [string(data[@alias='bibYear']) &lt; '1930']" >
    <xsl:value-of select="@nodeName"/> &nbsp; <xsl:value-of select="./data [@alias = 'bibYear']" />
    <br/>
    </xsl:if>


    </xsl:for-each>

    </xsl:template>

     

    Cheers

    Alec

  • Alec Colebrook-Clark 134 posts 258 karma points
    Sep 07, 2009 @ 16:48
    Alec Colebrook-Clark
    0

    Apologies there is still some testing code in the sample i provided.

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    Sep 07, 2009 @ 17:23
    Douglas Robar
    4

    You can do a lot with xslt, but to be honest, I'd clean up the source data and re-import. That will make all your xslt easier and also provide a good basis moving forward. The old rule of 'garbage in, garbage out' is certainly the case here and is a common problem when importing legacy data.

    BTW, you might want to have two date fields if you need date ranges. Possibly use a real date field, or a strictly formatted textstring (which you can validate with regex on the docType for any new items that are added once the data is in umbraco).

    cheers,
    doug.

  • dandrayne 1138 posts 2262 karma points
    Sep 07, 2009 @ 17:24
    dandrayne
    0

    It may be easier to re-import the database, but hows about a function inline in xslt (c#, vb, js) that would clean the dates and return either only the numbers or months? 

    How effective it will be depends on how different the stored date values are, but I imagine getting either only numbers or the month as text wouldn't be too difficult.  You could also check it the year number two digits (e.g. 07) or 4 digits (e.g. 1997) and adjust accordingly.

  • dandrayne 1138 posts 2262 karma points
    Sep 07, 2009 @ 17:25
    dandrayne
    0

    +1 for "garbage in, garbage out" !

  • Alec Colebrook-Clark 134 posts 258 karma points
    Sep 08, 2009 @ 10:45
    Alec Colebrook-Clark
    0

    Thanks for the feedback.

    I only realised how messy the original database was AFTER the import (i had a huge problem with that too, but that was of my own stupidity). I shall attempt to tidy up the database.

     

    Thanks

    Alec

  • 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