Copied to clipboard

Flag this post as spam?

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


  • Daniel Draper 36 posts 57 karma points
    Apr 05, 2010 @ 03:51
    Daniel Draper
    1

    Importing XSLT to prevent duplication

    I have implemented paging into a client website but would like to reduce the amount of duplicated XSLT. The idea goes like this on the paging macro I have a property that accepts a string this string is the name of the XSLT file to import. The import sends the node as a parameter and then the imported file handles the specifics surrounding the formatting. Here is an example... It's not working and I am not 100% sure why, can someone assist me please.

    <xsl:import href="format-video-list.xslt" />
    <xsl:template match="/">
        <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias = 'umbracoNaviHide']) != '1']">
            <xsl:apply-templates select="foo">
                <xsl:with-param name="foo-param" select="."/>
            </xsl:apply-templates>
        </xsl:for-each>
    </xsl:template>

    the template applied should be the template from the imported file. What am I missing I assume it's something simple?

     

    Cheers, Daniel

  • Daniel Draper 36 posts 57 karma points
    Apr 05, 2010 @ 03:53
    Daniel Draper
    0

    Sorry forgot to add the imported files content.

    <xsl:template match="foo">
        <xsl:param name="foo-param" />

        <xmp>
            <xsl:copy-of select="$foo-param" />
        </xmp>
    </xsl:template>
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 05, 2010 @ 09:03
    Sebastiaan Janssen
    0

    You might be running into a problem that is detailed on the old forum. Basically, you'll have to save (in the Umbraco backend) the file that calls the import. So if you make any changes to format-video-list.xslt, you also have to save the xslt files that import this file.

    I am have not yet tested this, but I'm assuming that you'll need to re-save ALL of the templates that call format-video-list.xslt because there is some compiling going on. 

    If you could report back to see if you'd need to re-save all of the calling files that would be great, thanks!

  • Daniel Draper 36 posts 57 karma points
    Apr 05, 2010 @ 09:51
    Daniel Draper
    0

    I did read the old post and re-saved all the files but I am still having an issue. I added the following code to the XSLT that was trying to import the formatting of each nodes contents and it returned 1 ID which was the source ID:

    <xsl:apply-imports />

    Any other ideas?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 05, 2010 @ 10:05
    Sebastiaan Janssen
    0

    Okay cool, I have it now, you're sending the node's value to your template, instead of the node's content, try changing it to this:

    <xsl:with-param name="foo-param">
      <xsl:copy-of select=".">
    </xsl:with-param>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 05, 2010 @ 21:13
    Chriztian Steinmeier
    0

    Hi Daniel,

    It seems you've missed an important piece of information regarding templates in XSLT: The match attribute specifies a pattern that should match a set of elements in the source XML, e.g. "data", "root/node" or "node[@nodeTypeAlias = 'Home']". When you specify "foo" as a match pattern, your template won't ever be instantiated because the Umbraco XML hasn't got a "foo" element (you're not using the 4.1beta2, are you?)

    You can use a name attribute instead, and achieve the desired behaviour, but then you should use call-template instead of apply-templates on the calling end.

    So let's try both - first using what I think you were aiming for:

    Template in "format-video-list.xslt" (note I use the name attribute):

    <xsl:template name="foo">
        <xsl:param name="foo-param" />
    
        <xmp>
            <xsl:copy-of select="$foo-param" />
        </xmp>
    </xsl:template>
    

    You should do this in the importing file:

    <xsl:variable name="nodeContainer" select="umbraco.library:GetXmlNodeById($source)" />
    <xsl:template match="/">
        <xsl:for-each select="$nodeContainer/node[not(data[@alias = 'umbracoNaviHide'] = 1)]">
            <xsl:call-template name="foo">
                <xsl:with-param name="foo-param" select="." />
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>
    

    Now, let's try it the other way:

    Template in "format-video-list.xslt":

    <xsl:template match="node">
        <xmp>
            <xsl:copy-of select="." />
        </xmp>
    </xsl:template>

    and then in the file that imports it, you can just do this:

    <xsl:variable name="nodeContainer" select="umbraco.library:GetXmlNodeById($source)" />
    
    <xsl:template match="/">
        <xsl:apply-templates select="$nodeContainer/node[not(data[@alias = 'umbracoNaviHide'] = 1)]" />
    </xsl:template>

     

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft