Subject: Re: [xsl] variable scope From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 21 Aug 2008 22:25:31 -0400 |
I've got a situation where an attribute may or may not be set. I'm building a postgres ddl from xml source that looks like:
... <views> <view name="super.av_address" source="super"/> <view name="brand.av_address" source="brand"/> <view name="av_address" source="agentviaconsumer" schema="agent" /> <view name="av_address" source="consumer" schema="consumer"/> <view name="av_address" source="fast_consumer" schema="fast_consumer"/> </views> ...
(Warning: I am going to use the term 'schema' in a postgres relational context in this paragraph, not the xml context!). Sometimes I have a view name which contains the schema in the name attribute, like the first two above. Then sometimes I have the schema defined in the schema attribute, like the last three. It's easy enough to get the data from the attributes into variables sname and vname like:
<xsl:for-each select="//views/view"> <xsl:choose> <xsl:when test="@source = 'super'"> <xsl:choose> <xsl:when test="@schema"> <xsl:variable name="sname" select="@schema"/> <xsl:variable name="vname" select="@name"/> <xsl:variable name="tname" select="str:replace($vname,'av_','at_')"/> <xsl:call-template name="create-super-view">
<xsl:with-param name="schemaname" select="$sname"/>
<xsl:with-param name="viewname" select="$vname"/>
<xsl:with-param name="tablename" select="$tname"/> </xsl:call-template>
<xsl:call-template name="create-super-view"> <xsl:with-param name="schemaname" select="@schema"/> <xsl:with-param name="viewname" select="@name"/> <xsl:with-param name="tablename" select="str:replace($vname,'av_','at_')"/> </xsl:call-template>
However, it would be so much more readable if I could do the variable assignment one time, something like:
<xsl:variable name="sname"> <xsl:choose> <xsl:when.... </xsl:variable> <xsl:variable name="vname"> <xsl:choose> <xsl:when... </xsl:variable>
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] variable scope, Greg Fausak | Thread | Re: [xsl] variable scope, Greg Fausak |
RE: [xsl] Oxygen editor very slow, Bordeman, Chris | Date | Re: [xsl] variable scope, Greg Fausak |
Month |