Nathan Nadeau <ndn <at> gleim.com> writes:
> A variable's scope in XSLT is only the containing block/element. 
> Therefore if you define a variable in an <xsl:if>, it is only in scope 
> with that <xsl:if> block, which is why it's telling you that $filename 
> is undefined when you try to reference it outside of the <xsl:if>. If 
> you need to compute a variable based on some conditions, you would put 
> the conditions within the <xsl:variable> definition block.

Good point. I ended up with something like this:

<xsl:variable name="filename">
  <xsl:choose>
    <xsl:when test="@NAME='CODE1'">
      <xsl:value-of select="concat($outputDir,'/fr/int.xml')" />
    </xsl:when>
    <xsl:when test="@NAME='CODE2'">
      <xsl:value-of select="concat($outputDir,'/fr/can.xml')" />
    </xsl:when>
  </xsl:choose>
</xsl:variable>


> Your code could be put into a template with a parameter representing the 
> language, and use the parameter to build your output directory, then 
> call the template as many times as needed with the appropriate language 
> parameter. Basic idea is to use a variable for this value, rather than 
> rewriting the same code twice with only the path being different.

Duh! No kidding. And I'm already doing it with other parameters too.


> You can certainly set this up in a single XSLT using <xsl:apply 
> templates> with appropriate @select and/or @mode values. You would then 
> write templates that match what you want to process, pull out only the 
> things you want, rename whatever you want, and redirect to the desired 
> output file. Then it's just a question of applying those templates in 
> the desired order.

Hmmm... I'll think a bit more about this. I'm not picturing it in my head, 
but I haven't tried to do it either. I'll try it out first then come back
when I'm stuck.

Thanks,

L


Reply via email to