Subject: [xsl] Re: implementing for-each for comparision From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Fri, 3 Oct 2003 08:27:00 +0200 |
This transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <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> <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:choose> <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)"/> </xsl:if> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(@Name, ' FILLER char terminated by ', $AP, '`', $AP)"/> </xsl:otherwise> </xsl:choose> <xsl:if test="position() != last()"> <xsl:value-of select="',
'"/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> when applied on your source.xml (for convenience I merged the two files into a single one): <Root> <Tables> <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> </Tables> <FixedTables> <Table Name="T1"> <Column Name="Col1" /> <Column Name="Col2" /> <Column Name="Col3" /> <Column Name="Col4" /> <Column Name="Col5" /> </Table> </FixedTables> </Root> produces the wanted result: colVal1, colVal2, colVal3 Date "M/DD/YYYY HH:MI:SS AM", Col4 FILLER char terminated by '`', colVal5 ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL "Dipesh Khakhkhar" <dkhakhkh@xxxxxxxxxxxxxxx> wrote in message news:3F7DF6AD@xxxxxxxxxxxxx > Hi, > > I am having xml like this. > Input xml (File1) > ---------- > <Root> > <Tables> > <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> > </Table> > <Root> > > =================================================================== > > I am reding one more xml file for mapping columns. I am reading it using > document function. This xml gives me the name of the column for which data is > available in the datafile. > > Document Mapping xml (File2) > -------------------- > <Root> > <FixedTables> > <Table Name="T1"> > <Column Name="Col1" /> > <Column Name="Col2" /> > <Column Name="Col3" /> > <Column Name="Col4" /> > <Column Name="Col5" /> > </Table> > </Root> > > > I am creating a text file(basically control file which i am feeding to sql > loader) out of it and needs output like this. I am showing a part of my > desired output. > > Desried output (File3) > -------------- > INTO TABLE tableName1 > ( > colVal1, > colVal2, > colVal3 Date "MM/DD/YYYY HH:MI:SS AM", > col4 FILLER char terminated by '`', > colVal5 > ) > > ==================================================================== > > I am able to get the output properly if there is no col4 in the mapping file > i.e. file2 then not writing line 5 above in the output. > > I want to implement something like > 1) Read each column from the File1. > 2) Match it will all the columns of File2 > 3) If name of column is same then get the value of column from file1 and > check if datatype attribute is date then output "Date MM:DD:YYYY HH:MI:SS AM" > otherwise don't do anything. > 4) If match exit from the for loop (is this possible in xsl) > 5) After doing match for all the columns of file1, whichever columns of file2 > are not matched shall be written within parenthesis like > "Column@Name (from file2) FILLER char terminated by '`'. As shown in the above > desired output col4 came only once in the output for matching all the columns > of File1 with that of file2. > > I hope i am clear in explaining my problem. > Any help to implement the above logic would be highly appreciated. > > Eagerly waiting for reply. > > Regards, > Dipesh > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] implementing for-each for com, Dipesh Khakhkhar | Thread | RE: [xsl] implementing for-each for, Jarno . Elovirta |
RE: [xsl] implementing for-each for, Jarno . Elovirta | Date | RE: [xsl] XSL:FO - How to wrap non-, David . Pawson |
Month |