[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Number of scans required ??
Subject: RE: [xsl] Number of scans required ?? From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx> Date: Sun, 17 Aug 2003 12:36:55 -0400 |
Hi, Thanks Gurus !! I will use this and try to solve my problem. I will inform you whether i will be able to compose transformation successfully. Anyway thanks a lot. This will surely help me. Regards, Dipesh Date: Fri, 15 Aug 2003 17:52:17 -0400 From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Subject: RE: [xsl] Number of scans required ?? Hi Dipesh, If I understand correctly, you want first to output the text data of a set of nodes, consisting of one node each for each of the values of COLUMN/@NAME in your document. That's what this line in your output is: >Agent Name,Install Path,Product Version,Build Number Then after that, you want to output a line for every ROW element in your input, which, for every @NAME value in your set of unique names, contains the value of the COLUMN in that row with the same @NAME. If none exists, you want an empty string. All the values, in every case, are separated by commas. Right? (This kind of statement of the problem is important because it expresses the output we want in terms of the input we have: the first step towards writing a declarative program to get it.) Given the problem statement, it's interesting that you wanted to do "two scans", since we have the problem of aggregating the set of @NAME values that can occur in the document. There are several ways to do this, including using two passes or a function to create a node set (which can in effect give us two passes within a single run of a stylesheet); a method closer to brute force also works, however: <xsl:variable name="name-set" select="//@NAME[not(.=preceding::@NAME)"/> This variable assignment basically collects all the @NAME attributes in the document, and keeps only those whose value is not represented among any of its preceding @NAME attributes -- in other words, a de-duplicated set. Given this, the task is much easier. Our root template simply iterates over this set and writes all the names, with a comma after each one but the last. Then when it has done that, it applies templates to all the rows in the document to process them in turn: <xsl:template match="/"> <xsl:for-each select="$name-set"> <xsl:value-of select="."/> <xsl:if test="not(position()=last())">,</xsl:if> </xsl:for-each> <xsl:text>
</xsl:text><!-- line feed for legibility --> <xsl:apply-templates select="//ROW"/> <!-- this apply-templates could be written to be more efficient, but I'm too lazy --> </xsl:template> Now all we need is a template to process our ROW elements. It runs over the same set of unique values, only this time giving us the value of the corresponding COLUMN in the row: <xsl:template match="ROW"> <!-- we bind our context node to a variable so we can get to it inside the for-each --> <xsl:variable name="this-row" select="."/> <!-- Now we put out whatever value we have for each node in our name set --> <xsl:for-each select="$name-set"> <xsl:value-of select="$this-row/COLUMN[@NAME=current()]"/> <xsl:if test="not(position()=last())">,</xsl:if> </xsl:for-each> <xsl:text>
</xsl:text><!-- line feed for legibility --> </xsl:template> There are a couple of things you need to understand fully in order to see why this works, mainly XPath things ... ask again if they aren't clear. BTW, this isn't tested, but aside from possible typos it should work.... I hope that helps, Wendell Date: Thu, 14 Aug 2003 15:58:35 +0100 From: David Carlisle <davidc@xxxxxxxxx> Subject: Re: [xsl] Number of scans required ?? Ah an earlier message of yours made the example clearer, OK this version first finds the longest row anywhere and then outputs all cells from all rows in the order of that longest row, filling out with blanks as needed (if some shorter rows may have columns that do not appear in the longest row, you have to work a bit harder) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Number of scans required , Wendell Piez | Thread | RE: [xsl] Number of scans required , Dipesh Khakhkhar |
RE: [xsl] CSV file from an XML sour, G. Ken Holman | Date | RE: [xsl] CSV file from an XML sour, Matt Trimmer |
Month |
Keywords