macaroni Posted May 28, 2004 Posted May 28, 2004 I'm having some trouble on how to get out multiple <data> that is contained in a single <col> element. It only prints out the first <data> element when a <col> element has multiple <data> elements. The 9th <col> has the related <data> and in some cases may not have any. What I am atempting is the format below: Question Text 1 Question Text 2 related data 2a related data 2b related data 2c Question Text 3 Below is an example of the XML file: <?xml version="1.0" encoding="UTF-8" ?> <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <ERRORCODE> 0 </ERRORCODE> <PRODUCT BUILD="03-05-2004" NAME="FileMaker Pro" VERSION="7.0v1a" /> <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="EvalSystem" RECORDS="2" TIMEFORMAT="h:mm:ss a" /> <METADATA> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="EvaluationID" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ApplicationID" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QuestionID" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QuestionType" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="HasCommentsFlag" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SelectionType" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SelectionRatings" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QuestionText" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QSTNITEMS::ItemDescription" TYPE="TEXT" /> </METADATA> <RESULTSET FOUND="2"> <ROW MODID="1" RECORDID="1"> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> TTE </DATA> </COL> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> Single Select </DATA> </COL> <COL> <DATA> No </DATA> </COL> <COL> <DATA> Radio </DATA> </COL> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> Please rate your experience </DATA> </COL> <COL> </COL> </ROW> <ROW MODID="1" RECORDID="2"> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> TTE </DATA> </COL> <COL> <DATA> 2 </DATA> </COL> <COL> <DATA> Matrix Selection </DATA> </COL> <COL> <DATA> No </DATA> </COL> <COL> <DATA> Radio </DATA> </COL> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> Please rate each of the following activities </DATA> </COL> <COL> <DATA> Center Tour </DATA> <DATA> Meet and Greet </DATA> <DATA> QA Sessions </DATA> </COL> </ROW> </RESULTSET> </FMPXMLRESULT> and the XSLT: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fmp"> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" /> <xsl:template match="fmp:FMPXMLRESULT"> <html> <body> <table border="1" cellPadding="1" cellSpacing="1"> <xsl:call-template name="header" /> <xsl:for-each select="fmp:RESULTSET/fmp:ROW"> <xsl:variable name="qType" select="fmp:COL[4]/fmp:DATA" /> <!-- we check how to print the question based on the question type --> <xsl:choose> <!-- Single Selection Type --> <xsl:when test="contains($qType, 'Single')"> <tr> <td colspan="8"> <xsl:value-of select="fmp:COL[8]/fmp:DATA" /> </td> </tr> </xsl:when> <!-- Matrix Selection Type --> <xsl:otherwise> <tr> <td colspan="8"> <b> <xsl:value-of select="fmp:COL[8]/fmp:DATA" /> </b> <xsl:for-each select="fmp:COL[9]"> <xsl:value-of select="fmp:DATA" /> </xsl:for-each> </td> </tr> </xsl:otherwise> </xsl:choose> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template name="header"> <tr> <td align="middle"> <xsl:attribute name="colspan"> <xsl:call-template name="numfields" /> </xsl:attribute> <xsl:text> Database: </xsl:text> <xsl:value-of select="fmp:DATABASE/@NAME" /> </td> </tr> <tr> <td align="middle"> <xsl:attribute name="colspan"> <xsl:call-template name="numfields" /> </xsl:attribute> <xsl:text> Records: </xsl:text> <xsl:value-of select="fmp:DATABASE/@RECORDS" /> </td> </tr> <tr> <xsl:for-each select="fmp:METADATA/fmp:FIELD"> <td align="middle"> <xsl:value-of select="@NAME" /> </td> </xsl:for-each> </tr> </xsl:template> <xsl:template name="numfields" match="fmp:METADATA"> <xsl:value-of select="count(fmp:METADATA/child::*)" /> </xsl:template> </xsl:stylesheet>
h2o.be Posted May 29, 2004 Posted May 29, 2004 Replace the lines <xsl:for-each select="fmp:COL[9]"> <xsl:value-of select="fmp:DATA" /> </xsl:for-each> with <xsl:apply-templates select="fmp:COL[9]/fmp:DATA"/> and add this template <xsl:template match="fmp:COL[9]/fmp:DATA"> <xsl:value-of select="."/> <br/> </xsl:template> the <br /> tag is just there for example
macaroni Posted May 31, 2004 Author Posted May 31, 2004 Thanks for the help. I do have a follow up question, I want to create a format similar to below: Please rate each of the following: Activity 1 Poor Fair Good Great Excellent Activity 2 Poor Fair Good Great Excellent Activity 3 Poor Fair Good Great Excellent With the sample XML below and using the stylesheet that I altered following your lead of using matching templates. I can pull out the "Poor Fair Good Great Excellent" only once but this time I need to print it out the same number of times as the same number of <data> elements in column 9. I initially thought of putting it in <xsl:otherwise> <xsl:apply-templates select="fmp:COL[9]/fmp:DATA" /> <xsl:apply-templates select="fmp:COL[10]/fmp:DATA" /> </xsl:otherwise> but then this would only process the node for col 9 then process node 10. I think what I need is <xsl:template name="fmp:COL[9]/fmp:DATA" > <xsl:value-of select="." /> <!-- process node col 10.--> which is the following::sibling of col 9 </xsl:template> I can't seem to figure out how to process one data element of col 9 then process col 10. Any help is much appreciated. Sample XML file <?xml version="1.0" encoding="UTF-8" ?> <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <ERRORCODE> 0 </ERRORCODE> <PRODUCT BUILD="03-05-2004" NAME="FileMaker Pro" VERSION="7.0v1a" /> <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="EvalSystem" RECORDS="2" TIMEFORMAT="h:mm:ss a" /> <METADATA> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="EvaluationID" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ApplicationID" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QuestionID" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QuestionType" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="HasCommentsFlag" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SelectionType" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="RatingGroup" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QuestionText" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QSTNITEMS::ItemDescription" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="RATINGOPTNS::RatingDesc" TYPE="TEXT" /> </METADATA> <RESULTSET FOUND="1"> <ROW MODID="2" RECORDID="2"> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> TTE </DATA> </COL> <COL> <DATA> 2 </DATA> </COL> <COL> <DATA> Matrix Selection </DATA> </COL> <COL> <DATA> No </DATA> </COL> <COL> <DATA> Radio </DATA> </COL> <COL> <DATA> 1 </DATA> </COL> <COL> <DATA> Please rate each of the following activities </DATA> </COL> <COL> <DATA> Center Tour </DATA> <DATA> Meet and Greet </DATA> <DATA> Training </DATA> </COL> <COL> <DATA> Poor </DATA> <DATA> Fair </DATA> <DATA> Good </DATA> <DATA> Great </DATA> <DATA> Excellent </DATA> </COL> </ROW> </RESULTSET> </FMPXMLRESULT> XSLT file: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet exclude-result-prefixes="fmp" version="1.1" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output doctype-public="xml" encoding="UTF-8" indent="yes" method="xml" version="1.0"/> <xsl:template match="fmp:FMPXMLRESULT"> <xsl:apply-templates select="fmp:RESULTSET/fmp:ROW"/> </xsl:template> <xsl:template match="fmp:RESULTSET/fmp:ROW"> <xsl:variable name="qtype" select="fmp:COL[4]/fmp:DATA" /> <xsl:variable name="allowComments" select="fmp:COL[5]/fmp:DATA" /> <xsl:value-of select="fmp:COL[8]/fmp:DATA" /> <xsl:choose> <xsl:when test="contains($qtype, 'Single')"> <xsl:apply-templates select="fmp:COL[10]/fmp:DATA" /> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="fmp:COL[9]/fmp:DATA" /> </xsl:otherwise> </xsl:choose> <xsl:if test="contains($allowComments, 'Yes')"> <!-- put input type="text" here --> </xsl:if> </xsl:template> <xsl:template match="fmp:COL[9]/fmp:DATA"> -<xsl:value-of select="." /> </xsl:template> <xsl:template match="fmp:COL[10]/fmp:DATA"> -<xsl:value-of select="." /> </xsl:template> </xsl:stylesheet>
h2o.be Posted May 31, 2004 Posted May 31, 2004 One little correction : <xsl:template match="fmp:COL[9]/fmp:DATA"> -<xsl:value-of select="." /> <xsl:apply-templates select="../../fmp:COL[10]/fmp:DATA" /> </xsl:template> Then the output is : ease rate each of the following activities - Center Tour - Poor - Fair - Good - Great - Excellent - Meet and Greet - Poor - Fair - Good - Great - Excellent - Training - Poor - Fair - Good - Great - Excellent
macaroni Posted June 1, 2004 Author Posted June 1, 2004 Jean-Marie, Thank you very much for your help. I should really start reading my XSLT tutorial again as I am getting rusty again. Thanks.
Recommended Posts
This topic is 7478 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now