Copied to clipboard

Flag this post as spam?

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


  • Rich Green 2246 posts 4008 karma points
    Jun 08, 2010 @ 19:03
    Rich Green
    0

    Hard coded node ids in XSLT

    I often end up referring to node id's directly within XSLT when nodes are outside of the website (for look ups for example)

    Something like: 

    <xsl:for-each select="umbraco.library:GetXmlNodeById('16572')">
        ....
    </xsl:for-each>

     

    This works fine but I'd prefer to have these values in a config file or similar somewhere and refer to them by name so I can keep track.

    Just wondering what how others deal with this?

    Cheers

    Rich

     

     

    .

  • Chris Dunn 210 posts 401 karma points
    Jun 08, 2010 @ 19:24
    Chris Dunn
    0

    For ease of maintainence you could set them as variables within the xslt vs  hardcoding them.  That way they are all at the top of the xslt and you don't need to search the code to make changes.

    -Chris

  • Jeff Grine 149 posts 189 karma points
    Jun 08, 2010 @ 19:31
    Jeff Grine
    0

    I try to go with nodeTypeAlias and/or tree structure for lookups, so I don't have to worry about resetting individual id's when moving from dev to test to prod.

  • Rich Green 2246 posts 4008 karma points
    Jun 08, 2010 @ 19:58
    Rich Green
    0

    Thanks guys.

    @Chris this is slightly better thanks,  I would still have to hunt through each XSLT file though.

    @Jeff this would be the preferred method, though sometimes it's just easier to refer by id. 

     

    Is there an easy way to read config values in XSLT?

     

     

     

     

     

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jun 08, 2010 @ 20:08
    Douglas Robar
    0

    Hi, Rich,

    You could either use a bit of .net to read a .config file (possibly over-kill in this situation) or you could use the built-in xslt document() function.

    For example...

    <xsl:variable name="xmlFileContent" select="document('c:\inetpub\umb403\data\myConfigData.xml')" />
    <xsl:copy-of select="$xmlFileContent" />

    You would obviously need the config file to be valid xml, but you could then parse it in your xslt to get the item you were looking for.

     

    Another option is to use a custom docType for the 'configuration' section of information that is outside your main content tree. Then you can use $currentPage/ancestor-or-self::root/node[@nodeTypeAlias = 'configSection']/blahblahblah. That would keep you from using the id directly and might be faster than reading an external file.

    Let us know what you finally decide.

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft