Copied to clipboard

Flag this post as spam?

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


  • Pete Naylor 21 posts 39 karma points
    Sep 26, 2012 @ 13:10
    Pete Naylor
    0

    Merging two XSLT files in memory.

    I have a client that displays documents links on their Umbraco site from an XML list.

    <rows>

    <row>

    <ID>1208</ID>

    <Edit>0</Edit>

    <DocIcon>pdf</DocIcon>

    <Title>06 Effluent Reuse Pilot Scheme at Ngong Ping Lantau Hong Kong</Title>

    <LinkFilename>006_Effluent_Reuse_Pilot_Scheme_at_Ngong_Ping_Lantau_Hong_Kong_.pdf</LinkFilename>

    <Modified>2010-03-04 18:49:32</Modified>

    <Editor>41;#Administrator</Editor>

    </row>

    </rows>

    I have a second XML file with sort information I need to combine with this document:

    <rows>

    <row>

    <ID>1208</ID>

    <SortOrder>53</SortOrder>

    </row>

    </rows>

    The first XML file is updated / overwritten every day with an up to date copy.
    I was wondering if there was an easy way to combine these two files into a variable using ID to match the data and then sort by ID.
    Any help would be appreciated

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 26, 2012 @ 13:18
    Chriztian Steinmeier
    0

    Hi Pete,

    Something like this should work (though haven't exactly tested it) :

            <!-- You can grab these however you need -->
        <xsl:variable name="doc-data" select="document('/path/to/file1.xml')" />
        <xsl:variable name="sorting" select="document('/path/to/file2.xml')" />
    
        <xsl:template match="/">
    
            <xsl:apply-templates select="$doc-data/rows/row">
                <xsl:sort select="$sorting/rows/row[ID = current()/ID]/SortOrder" data-type="number" order="ascending" />
            </xsl:apply-templates>
    
        </xsl:template>
    

    /Chriztian 

  • Pete Naylor 21 posts 39 karma points
    Sep 27, 2012 @ 11:37
    Pete Naylor
    0

    Thanks. That sorts the data, but then it outputs it to the page before I can format it.

    I'm a bit of a beginner at XSLT, how can I get the sorted data into a variable? I normally cycle through each node using the code below, but the I need to update the data in the variable to the sorted data.

    <xsl:for-each select="$xml/rows/row[contains(CMSPageUrl,$page) or contains(CMSPageUrl,'ALL')]">

     

    <li>

    <xsl:if test="position()=last()">

    <xsl:attribute name="class">

    last

    </xsl:attribute>

    </xsl:if>

    <xsl:call-template name="getTitle">

    <xsl:with-param name="icon" select="DocIcon" />

    <xsl:with-param name="title" select="Title"/>

    <xsl:with-param name="doc" select="LinkFilename"/>

    <xsl:with-param name="abbrev" select="Abbreviated_x0020_Title"/>

    </xsl:call-template>

    </li>

    </xsl:for-each> 

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 27, 2012 @ 11:49
    Chriztian Steinmeier
    0

    Hi Pete,

    If you add a template for the <row> elements, every row will be rendered through that, e.g.:

    <xsl:template match="row">
        <li>
            <xsl:if test="position()=last()">
                <xsl:attribute name="class">last</xsl:attribute>
            </xsl:if>
            <xsl:call-template name="getTitle">
                <xsl:with-param name="icon" select="DocIcon" />
                <xsl:with-param name="title" select="Title"/>
                <xsl:with-param name="doc" select="LinkFilename"/>
                <xsl:with-param name="abbrev" select="Abbreviated_x0020_Title"/>
            </xsl:call-template>
        </li>
    </xsl:template>

    And you can add the condition to the apply-templates statement:

    <xsl:apply-templates select="$doc-data/rows/row[contains(CMSPageUrl, $page) or contains(CMSPageUrl, 'ALL')]">

    /Chriztian

  • Pete Naylor 21 posts 39 karma points
    Sep 27, 2012 @ 13:42
    Pete Naylor
    0

    I've just tested it and it is working great. Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft