[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] xsl] Re: implementing for-each for comparision

Subject: [xsl] xsl] Re: implementing for-each for comparision
From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx>
Date: Fri, 3 Oct 2003 10:00:12 -0400


Thanks for replying.
I am sorry for my typo as pointed out by Jarno - VNV Nation: Legion
(Note that in the two example documents you use column names "col1" and 

So the mistake in my design to solve the problem was I was reading wrong file 
as my main input and reading other file using document. My mistake

You have reversed it and written a efficient x-path expression to get the 
proper match.

Thanks a lot once again. I will try to implement this logic into my original 

Dipesh Khakhkhar

Date: Fri, 3 Oct 2003 08:27:00 +0200
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Subject: [xsl] Re: implementing for-each for comparision

This transformation:

<xsl:stylesheet version="1.0"
<xsl:output method="text"/>
<xsl:variable name="AP">'</xsl:variable>
<xsl:variable name="Q">"</xsl:variable>
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>

<xsl:template match="/">
<xsl:apply-templates select="/*/FixedTables/Table"/>

<xsl:template match="FixedTables/Table">
<xsl:for-each select="Column">
<xsl:variable name="vlcName"
select="translate(@Name, $upper, $lower)"/>

<xsl:variable name="vMatchColumn"
select="/*/Tables/Table[@Name = current()/../@Name]/Column
[@Name = $vlcName]"/>
<xsl:when test="$vMatchColumn">
<xsl:value-of select="$vMatchColumn/@Value"/>
<xsl:if test="$vMatchColumn/@Datatype = 'date'">
<xsl:value-of select="' Date '"/>
<xsl:value-of select="concat($Q, 'M/DD/YYYY HH:MI:SS AM', $Q)"/>
' FILLER char terminated by ', $AP, '`', $AP)"/>
<xsl:if test="position() != last()">
<xsl:value-of select="',&#xA;'"/>

when applied on your source.xml (for convenience I merged the two files into
a single one):

<Table Name="T1" Value="tableName1">
<Column Name="col1" Value="colVal1" Datatype="char"/>
<Column Name="col2" Value="colVal2" Datatype="char"/>
<Column Name="col3" Value="colVal3" Datatype="date"/>
<Column Name="col5" Value="colVal5" Datatype="char"/>
<Table Name="T1">
<Column Name="Col1" />
<Column Name="Col2" />
<Column Name="Col3" />
<Column Name="Col4" />
<Column Name="Col5" />

produces the wanted result:

colVal3 Date "M/DD/YYYY HH:MI:SS AM",
Col4 FILLER char terminated by '`',


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

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

Current Thread