Subject: Re: [xsl] How to compare values between two different looping tags From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 25 Jul 2002 19:57:32 -0400 |
I have an xml file like below. ... How do you write an xsl to get a text output like below?
C D E ======================= 111 222 000 232 3232 777
T:\ftemp>type murali.xml <?xml version="1.0" encoding="iso-8859-1"?> <G> <X> <A> <C>111</C> <D>222</D> </A> <A> <C>232</C> <D>3232</D> </A> </X>
<Y> <B> <C>232</C> <E>777</E> </B> <B> <C>111</C> <E>000</E> </B> <B> <C>232</C> <E>777</E> </B> </Y> </G> T:\ftemp>type murali.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="allC" match="C" use="."/> <xsl:key name="allD" match="D" use="."/> <xsl:key name="allE" match="E" use="."/>
<xsl:variable name="countC" select="count($uniqC)"/> <xsl:variable name="countD" select="count($uniqD)"/> <xsl:variable name="countE" select="count($uniqE)"/>
<xsl:template match="/"> <xsl:choose> <xsl:when test="$countC >= $countD and $countC >= $countE"> <xsl:call-template name="dorows"> <xsl:with-param name="longest" select="$uniqC"/> </xsl:call-template> </xsl:when> <xsl:when test="$countD >= $countC and $countD >= $countE"> <xsl:call-template name="dorows"> <xsl:with-param name="longest" select="$uniqD"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="dorows"> <xsl:with-param name="longest" select="$uniqE"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="dorows"> <xsl:param name="longest"/> C D E ====================== <xsl:for-each select="$longest"> <xsl:variable name="index" select="position()"/> <xsl:for-each select="$uniqC"> <xsl:sort select="." data-type="number"/> <xsl:if test="$index = position()"> <xsl:choose> <xsl:when test="$countC >= $index"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:text> </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> <xsl:text> </xsl:text> <xsl:for-each select="$uniqD"> <xsl:sort select="." data-type="number"/> <xsl:if test="$index = position()"> <xsl:choose> <xsl:when test="$countD >= $index"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:text> </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> <xsl:text> </xsl:text> <xsl:for-each select="$uniqE"> <xsl:sort select="."/> <xsl:if test="$index = position()"> <xsl:choose> <xsl:when test="$countE >= $index"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:text> </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> <xsl:text> </xsl:text> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
C D E ====================== 111 222 000 232 3232 777
T:\ftemp>echo Done! Done!
-- Upcoming hands-on in-depth 3-days XSLT/XPath and/or 2-days XSL-FO: - North America: Sep 30-Oct 4,2002 - Japan: Oct 7-Oct 11,2002
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-07-1 Practical Formatting Using XSLFO XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed), articles, training (instructor-live,Internet-live,web/CD,licensed) Next public training: 2002-08-05,26,27,09-30,10-03,07,10
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to compare values between, murli bk | Thread | Re: [xsl] How to compare values bet, murli bk |
[xsl] why xml, why not use ado reco, Greg Fichter | Date | Re: [xsl] Problem Using Javascript , stoneson |
Month |