yarivt Posted April 11, 2008 Share Posted April 11, 2008 Hi,This simple code doesn't work in my IE. If the <xsl:variable> statement is local inside <xsl:template match="Search"> then it works, but I want this variable to be one level higher (kind of global).What am I doing wrong?By the way, any suggestions of how to get a counter in a way that each "Search" item displays with higher font size?var.xml: <?xml version="1.0" encoding="Windows-1255"?><?xml-stylesheet type="text/xsl" href="var.xsl"?><OpeningScreen> <Search> <Text>money</Text> <Link>SearchAll?text="money"</Link> </Search> <Search> <Text>dollar</Text> <Link>SearchAll?text="dollar"</Link> </Search> <Search> <Text>tax</Text> <Link>SearchAll?text="tax"</Link> </Search></OpeningScreen> var.xsl: <?xml version="1.0" encoding="Windows-1255"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><HTML><BODY><xsl:apply-templates select="OpeningScreen"/></BODY></HTML></xsl:template><xsl:template match="OpeningScreen"><xsl:variable name="bodyTextSize">10pt</xsl:variable> <xsl:apply-templates select="Search"/></xsl:template><xsl:template match="Search"> <A><xsl:attribute name="href"><xsl:value-of select="Link"/></xsl:attribute> <font size="{$bodyTextSize}"> <xsl:value-of select="Text"/> </font> </A> | </xsl:template></xsl:stylesheet> Thanks, Yariv Link to comment Share on other sites More sharing options...
boen_robot Posted April 11, 2008 Share Posted April 11, 2008 XSLT variables are either legal inside a template (alone!) or in the whole stylesheet. Add in on the top of the stylesheet if you want it global i.e. <?xml version="1.0" encoding="Windows-1255"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:variable name="bodyTextSize">10pt</xsl:variable><xsl:template match="/"><HTML><BODY><xsl:apply-templates select="OpeningScreen"/></BODY></HTML></xsl:template><xsl:template match="OpeningScreen"> <xsl:apply-templates select="Search"/></xsl:template><xsl:template match="Search"> <A><xsl:attribute name="href"><xsl:value-of select="Link"/></xsl:attribute> <font size="{$bodyTextSize}"> <xsl:value-of select="Text"/> </font> </A> | </xsl:template></xsl:stylesheet> If you want it to be available from a certain template on, you'll have to declare it everywhere else, but pass the original value everywhere. Sort's like: <?xml version="1.0" encoding="Windows-1255"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><HTML><BODY><xsl:apply-templates select="OpeningScreen"/></BODY></HTML></xsl:template><xsl:template match="OpeningScreen"><xsl:param name="bodyTextSize">10pt</xsl:variable> <xsl:apply-templates select="Search"> <xsl:with-param name="bodyTextSize" select="$bodyTextSize"/> </xsl:apply-templates></xsl:template><xsl:template match="Search"><xsl:param name="bodyTextSize"/> <A><xsl:attribute name="href"><xsl:value-of select="Link"/></xsl:attribute> <font size="{$bodyTextSize}"> <xsl:value-of select="Text"/> </font> </A> | </xsl:template></xsl:stylesheet> The later bodyTextSize will get whatever the value of the first bodyTextSize is. The time between one template and another is the time when the value of a parameter can be adjusted actually. If you run the same template recursively, you can adjust the value a little every time. Link to comment Share on other sites More sharing options...
yarivt Posted April 13, 2008 Author Share Posted April 13, 2008 XSLT variables are either legal inside a template (alone!) or in the whole stylesheet. Add in on the top of the stylesheet if you want it global i.e.<?xml version="1.0" encoding="Windows-1255"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:variable name="bodyTextSize">10pt</xsl:variable><xsl:template match="/"><HTML><BODY><xsl:apply-templates select="OpeningScreen"/></BODY></HTML></xsl:template><xsl:template match="OpeningScreen"> <xsl:apply-templates select="Search"/></xsl:template><xsl:template match="Search"> <A><xsl:attribute name="href"><xsl:value-of select="Link"/></xsl:attribute> <font size="{$bodyTextSize}"> <xsl:value-of select="Text"/> </font> </A> | </xsl:template></xsl:stylesheet> If you want it to be available from a certain template on, you'll have to declare it everywhere else, but pass the original value everywhere. Sort's like: <?xml version="1.0" encoding="Windows-1255"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><HTML><BODY><xsl:apply-templates select="OpeningScreen"/></BODY></HTML></xsl:template><xsl:template match="OpeningScreen"><xsl:param name="bodyTextSize">10pt</xsl:variable> <xsl:apply-templates select="Search"> <xsl:with-param name="bodyTextSize" select="$bodyTextSize"/> </xsl:apply-templates></xsl:template><xsl:template match="Search"><xsl:param name="bodyTextSize"/> <A><xsl:attribute name="href"><xsl:value-of select="Link"/></xsl:attribute> <font size="{$bodyTextSize}"> <xsl:value-of select="Text"/> </font> </A> | </xsl:template></xsl:stylesheet> The later bodyTextSize will get whatever the value of the first bodyTextSize is. The time between one template and another is the time when the value of a parameter can be adjusted actually. If you run the same template recursively, you can adjust the value a little every time. Thanks :-) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.