[xsl] Hopefully not a terribly silly question

Subject: [xsl] Hopefully not a terribly silly question
From: Morgan Goeller <morganworks@xxxxxxx>
Date: Thu, 03 Jan 2002 10:21:36 -0700
Hello all!


This is my first posting to the list, and I hope it is not a terribly silly question. I normally try like the dickens not to have to ask for help on mailing lists, but after searching the archives and the web I can't seem to come up with an answer. Please bear with me. I am using a product called ODBC Socket Server, which allows UNIX machines to get ODBC information from Windows boxes. The information is returned as XML data which looks something like this:


<result state="success">
<row>
<column name="aspect_task_id">70006</column>
<column name="aspect_task_descr">Tucson - Update CCIS_SISO_SUMMARY</column>
<column name="dep_task_descr">End of Switch Procedures - tuc</column>
<column name="dep_task_id">70290</column>
<column name="dep_task_grp">Aspect Data Loads</column>
</row>
<row>
<column>70007</column>
<column>Tucson HQ - Update CCIS_SISO_SUMMARY</column>
<column>End of Switch Procedures - tuchq</column>
<column>70390</column>
<column>Aspect Data Loads</column>
</row>
.
. .


</result>


I need to translate this into something like:


<row aspect_task_id="...." aspect_task_descr="......" dep_task_descr="....." dep_task_id="....." dep_task_grp="....." />
<row aspect_task_id="...." aspect_task_descr="......" dep_task_descr="....." dep_task_id="....." dep_task_grp="....." />
<row aspect_task_id="...." aspect_task_descr="......" dep_task_descr="....." dep_task_id="....." dep_task_grp="....." />
<row aspect_task_id="...." aspect_task_descr="......" dep_task_descr="....." dep_task_id="....." dep_task_grp="....." />
<row aspect_task_id="...." aspect_task_descr="......" dep_task_descr="....." dep_task_id="....." dep_task_grp="....." />



I am trying to iterate through each of the rows, then each of the columns. If I am not in the first column then I want to get a hold of the name attribute from the first row and apply it. I wrote a stylesheet that tries to grab just those attributes that looks like:


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output indent="yes"/>


<xsl:template match="/"> <xsl:for-each select="/result/row">
<xsl:for-each select="./column">
<xsl:call-template name="print_name"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>


<xsl:template name="print_name">
<xsl:choose>
<xsl:when test="@name"> Name = <xsl:value-of select="@name"/> </xsl:when>
<xsl:otherwise> Name <xsl:value-of select="position()"/>=
<xsl:value-of select="concat('/result/row[1]/column[', position(),']/@name')"/> Value <xsl:value-of select="position()"/>=<xsl:value-of select="."/> </xsl:otherwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>

Unfortunately, I get a the literal string result of the concat() function, instead of the actual data value. Is there some sort of eval() function that I need to use? Am I approaching this incorrectly? I know that XSL is quite a paradigm shift from traditional programming methods.

Morgan Goeller

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"For every complex problem, there is a solution that is simple, neat, and wrong."
-- H.L. Mencken (1880-1956)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread