Subject: Re: [xsl] problems with position() and following-sibling From: omprakash.v@xxxxxxxxxxxxx Date: Fri, 12 Aug 2005 15:40:02 +0530 |
Hi Georges, You can use this stylesheet to achieve what you want. <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lhp="hhscors"> <xsl:output method="html"/> <xsl:template match="/Row"> <xsl:apply-templates select="Cell"/> </xsl:template> <xsl:template match="Cell"> <xsl:choose> <xsl:when test="position() = 2"> <entry> <xsl:value-of select="."/> </entry> </xsl:when> <xsl:when test="position() = 3"> <entry> <xsl:value-of select="."/> <footnote> <para> <xsl:apply-templates select="parent::Row/*[self::Cell][position() = 7]" mode="ahead"/> </para> </footnote> </entry> </xsl:when> <xsl:when test="position() = 7"> </xsl:when> <xsl:when test="position() > 2 and position() < 6"> <entry> <xsl:value-of select="."/> </entry> </xsl:when> </xsl:choose> </xsl:template> <xsl:template match="Cell" mode="ahead"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> <!-- END xsl --> Cheers, prakash Georges Schmitz <georges.schmitz To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx @heitec.de> cc: (bcc: omprakash.v/Polaris) Subject: [xsl] problems with position() and following-sibling 08/12/2005 02:07 PM Please respond to xsl-list My use case: I have an Excel Sheet in xml format, that is basically build out of 6 columns. Now and then I have a value in column 7, that should be made a footnote in column 2 of the output. Column 1 is to be eliminated in the output (I just use it for grouping). Example Data (6 columns, sometimes 7): <Row> <Cell><Data ss:Type="String">LAS</Data></Cell> <Cell><Data ss:Type="String">Masterreport</Data></Cell> <Cell><Data ss:Type="String">alle 4 Lizenzarten</Data></Cell> <Cell><Data ss:Type="String">Lizenzdruck</Data></Cell> <Cell><Data ss:Type="String">Jasper</Data></Cell> <Cell><Data ss:Type="String">pilot_licence_CH.xml</Data></Cell> <Cell><Data ss:Type="String">Alle Lizenzvorlagen sind in zip-Dateien zusammengefasst.</Data></Cell> </Row> Output should be (5 columns): <row> <entry>Masterreport</entry> <entry>alle 4 Lizenzarten<footnote> <para>Alle Lizenzvorlagen sind in zip-Dateien zusammengefasst.</para> </footnote> </entry> <entry>Lizenzdruck</entry> <entry>Jasper</entry> <entry>pilot_licence_CH.xml</entry> </row> My approach is to use simple template matching for rows and cells: <xsl:template match="Row"> <row> <xsl:apply-templates/> </row> </xsl:template> <xsl:template match="Cell[position() > 1 and position() < 7]"> <entry> <xsl:value-of select="Data"/> <xsl:if test="position()=3 and following-sibling::Cell[7]"> <xsl:message>+++ making footnote +++</xsl:message> <footnote><para><xsl:value-of select="following-sibling::Cell[7]/Data"/></para></footnote> </xsl:if> </entry> </xsl:template> But this way, I don't get any footnote at all (probably, I'm using position() in an incorrect way?). While playing around with the line <xsl:if test="position()=3 and following-sibling::Cell[7]"> I got the impression that position() and following-sibling::e:Cell[x] do not see the "absolute" node positions of the cells in the original tree, but only the filtered set of the match by Cell[position() > 1 and position() < 7], which should result in 5 cells (am I right here?). In consequence, I tried to switch down the node number in the if statement, and with "5" I finally got footnotes (in the first cell) <xsl:if test="following-sibling::e:Cell[5]"> not really knowing why "5" and not "6" (if the position is calculated from the current context node of the first cell?). Any further attempts to refine the statement with position()=2, to move the footnote to the second column, didn't succeed. I have to admit, that my proceeding was "try and error" here (very unsatisfying to me), so can someone please point out, what is going on in my template. Thanks, Georges This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited. Visit Us at http://www.polaris.co.in
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] problems with position() , Michael Kay | Thread | Re: [xsl] problems with position() , Georges Schmitz |
Re: [xsl] Unique values in tags, António Mota | Date | Re: [xsl] problems with position() , Georges Schmitz |
Month |