Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 02, 2010 @ 12:07
    Sebastiaan Janssen
    0

    How to make include recognize it's parent's variables

    So I have three XSLT files mother.xslt and child1.xslt and child2.xslt.

    The mother.xslt has an xsl;variable that needs to be in place for both child1 and child2 to function correctly.

    However, Visual Studio does not know that the children are imported by the mother. So I see red squiggles every time that I use the mother's variable.

    Is there a way to tell VS to look at the mother for the variables?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 02, 2010 @ 12:31
    Chriztian Steinmeier
    1

    Hi Sebastiaan,

    I don't use VS so can not say for sure, but depending on your templates setup you might be able to fake something by declaring a local variable in the template using it and assigning it the value of the global variable:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
    
        <xsl:variable name="var" select="'Hello World'" />
    
        <xsl:include href="include1.xslt" />
    
        <xsl:template match="/">
            <xsl:value-of select="$var" />
    
            <xsl:call-template name="sub1" />
        </xsl:template>
    
    </xsl:stylesheet>
    
    
    
    <!-- In include1.xslt: -->
    <xsl:template name="sub1">
        <xsl:variable name="var" select="$var" />
        [<xsl:value-of select="$var" />]
    </xsl:template>
    

    /Chriztian

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 02, 2010 @ 13:38
    Sebastiaan Janssen
    0

    You sir, are absolutely correct! Thank you, I hate red squiggles!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 02, 2010 @ 14:48
    Sebastiaan Janssen
    0

    Shoot! I spoke too soon! The children now have no more squiggles, but they fail to load unless I remove the variables because they have the same name as an existing variable. So I guess the only solution is to do something like: 

    <xsl:variable name="var" select="$localVar" />

    Probably worth it though, to catch errors that I would've otherwise missed.

Please Sign in or register to post replies

Write your reply to:

Draft