[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] xsl] Re: implementing for-each for comparision
Hi, 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 "Col1",) 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 inputs. Regards, Dipesh Khakhkhar Date: Fri, 3 Oct 2003 08:27:00 +0200 From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Subject: Re: implementing for-each for comparision 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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|