Subject: RE: [xsl] Create table with optional elements From: "Ricardo Saraiva" <rss@xxxxxxxxxxxxxx> Date: Mon, 2 Jun 2003 15:27:56 +0100 |
Hello, Your code works ok, but I have another problem related to the same table. I can have more then one element on each column/row. My xml can be: <wn1:Term i:type="wn1:Term"> <wn1:data i:type="d:string">Client (of a shop)</wn1:data> <wn1:lang i:type="d:string">en</wn1:lang> </wn1:Term> <wn1:Term i:type="wn1:Term"> <wn1:data i:type="d:string">Clase de objeto</wn1:data> <wn1:lang i:type="d:string">es</wn1:lang> </wn1:Term> <wn1:Term i:type="wn1:Term"> <wn1:data i:type="d:string">Chaise longue 3</wn1:data> <wn1:lang i:type="d:string">fr</wn1:lang> </wn1:Term> <wn1:Term i:type="wn1:Term"> <wn1:data i:type="d:string">Transat</wn1:data> <wn1:lang i:type="d:string">fr</wn1:lang> </wn1:Term> the table row would be <tr> <td> Client (of a shop) </td> <td> Clase de objeto </td> <td> Chaise longue 3, Transat </td> </tr> How can I do this? Thanks in advance, Ricardo Saraiva. -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Martin Rowlinson (MarrowSoft) Sent: terça-feira, 27 de Maio de 2003 12:15 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Create table with optional elements Hi Ricardo, Assuming that you have your namespaces declared, e.g. <wn2:ArrayOfToken_Response i:type="wn1:ArrayOfToken" xmlns:wn2="namespace-wn2" xmlns:wn1="namespace-wn1" xmlns:i="namespace-i"> .... then try something like... <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wn2="namespace-wn2" xmlns:wn1="namespace-wn1" xmlns:i="namespace-i"> <xsl:output method="html" indent="yes"/> <!-- key for finding distinct columns --> <xsl:key name="kDistinctCols" match="wn1:lang" use="."/> <!-- find distinct columns here so that they can be re-used in different templates --> <xsl:variable name="DistinctCols" select="/wn2:ArrayOfToken_Response/wn1:Token/wn1:term/wn1:Term/wn1:lang[ generate-id() = generate-id(key('kDistinctCols',.))]"/> <xsl:template match="wn2:ArrayOfToken_Response"> <html> <body> <table border="1"> <!-- header row --> <tr> <xsl:for-each select="$DistinctCols"> <xsl:sort/> <th> <xsl:value-of select="."/> </th> </xsl:for-each> </tr> <!-- data rows --> <xsl:apply-templates select="wn1:Token"/> </table> </body> </html> </xsl:template> <xsl:template match="wn1:Token"> <xsl:variable name="this-terms" select="wn1:term/wn1:Term"/> <tr> <xsl:for-each select="$DistinctCols"> <xsl:sort/> <xsl:variable name="this-cell" select="$this-terms[wn1:lang = current()]"/> <td> <xsl:choose> <xsl:when test="$this-cell"> <xsl:value-of select="$this-cell/wn1:data"/> </xsl:when> <xsl:otherwise> <!-- do whatever you want to indicate no cell content --> <xsl:text>[none!]</xsl:text> </xsl:otherwise> </xsl:choose> </td> </xsl:for-each> </tr> </xsl:template> </xsl:stylesheet> Hope this helps Marrow http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger) http://www.topxml.com/Xselerator 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 -> |
---|---|---|
RE: [xsl] Finding immediately prece, Passin, Tom | Thread | [xsl] Can I change the namespace of, Graham Hannington |
Re: [xsl] Finding immediately prece, Betty Harvey | Date | Re: [xsl] RE: adding link to report, G. Ken Holman |
Month |