Hi,

I'm trying to do a number of things on a single input file and I find that the
approach I am taking is a bit bloated and cumbersome. So I'm looking for a
better way.

I have a data file which looks like this:

<datafile name="SOMECODE">
<data name_en="English name" name_fr="French name" some_id="Some unique ID">
  <info attr1_en="First English attr." attr_fr="First French attr."
      attr2_en="Var2 English" attr2_fr="Var2 French"/>
  <info ...>
  <info ...>
</data>

<data ...>
</data>

<data ...>
</data>
 .
 . 
 .
</datafile>

I am extracting the content of this file to create 4 different types of files.

I am creating several English files containing one <data> (and its <info>
children) element with only the English attributes, which are renamed from
attr1_en to attr1, attr2_en to attr2, name_en to name, etc.. A new element
called <Language> is added. The resulting file would look like this:

<datafile name="SOMECODE">
<Language>en</Language>
<data name="English name" some_id="Some unique ID">
  <info attr1="First English attr." attr2="Var2 English"/>
  <info ...>
  <info ...>
</data>
</datafile>

I also create several French files with a similar pattern applied to the French
elements and attributes.

I create one English file which contains the <datafile> element and the <data>
elements with the English attributes, but *not* the <info> children. It looks
like this:

<datafile name="SOMECODE">
<Language>en</Language>
<data name="English name" some_id="Some unique ID">
</data>

<data name="English name 1" some_id="Some unique ID 1">
</data>

<data name="English name 2" some_id="Some unique ID 2">
</data>

 .
 .
 .
</datafile>

Same thing for a French file.

In order to do this, I am using four(!) different XSL files and parsing the same
base document four times to get my results. Furthermore (as if this wasn't
enough), I have to change the naming convention of my output files depending on
the value of <datafile name="SOMECODE">.

After this long preamble, here are some specific questions:

1) How can I set a runtime variable depending on the value of SOMECODE? I 
tried: 

<xsl:template match="DATAFILE">

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

<redirect:write select="$filename" indent="yes">
 .
 .
 .
</redirect:write>
</xsl:template match="DATAFILE">

When I run it though, I get an error saying the "filename" variable is
undefined, however the message prints on stdout.

2) I created a second XSL file where the only difference from above is that the
"/en/" in the filename is changed to "/fr/". Is there a way for me to combine
that in the same XSL file?

3) I have another pair of XSL documents which act in a similar manner, but where
the difference is that I rename attributes based on language. In one case, it
deletes all **_fr attributes and removes the "_en" suffix from the others. The
second files deletes all **_en attributes and removes the "_fr" from the other
attributes.

In an ideal world, I would like to create a single XSL which would generate all
my output in one fell swoop, instead of making me parse the same data multiple
times and sending it through different XSLs. But maybe I'm dreaming in
Technicolor...

Thanks!

L

Reply via email to