NewJoizey Posted November 3, 2010 Share Posted November 3, 2010 When my transform runs, my output table looks something like this (note position of spaces rendered where empty <td> tags) =============================concert book signing=============================todaynew jersey new york============================ when what I need is this: =============================concert book signing=============================today new yorknew jersey ============================= the xml would look something like: <events> <event> <name>concert</name> <date>today</date> <time></time> <location>New Jersey</location> </event> <event> <name>book signing</name> <date></date> <time></time> <location>New York</location> </event></events> Can this be done using pure XSLT, or is it a better approach to somehow use server side code to manipulate this? Link to comment Share on other sites More sharing options...
boen_robot Posted November 3, 2010 Share Posted November 3, 2010 What's the XSLT you have so far?It can probably be done with XSLT, but I'm not completely sure what's the desired format you're looking for. Maybe seeing your XSLT will help. Link to comment Share on other sites More sharing options...
NewJoizey Posted November 3, 2010 Author Share Posted November 3, 2010 What's the XSLT you have so far?the example i posted is a simplified version of my actual problem, I can't post the actual code due to security concerns, so I will try to apply what i have done to the example:<table id="tblEvents"> <tr> <xsl:for-each select ="event[position() < 3]"> <th> <xsl:value-of select ="name" /> </th> </xsl:for-each> </tr><!-- I know this isn't right. It somehow needs to be iterated 3 times over, but I'm not sure how --> <tr> <xsl:for-each select ="event[position() < 3]"> <td> <xsl:choose> <xsl:when test="position() mod 2 != 0"> <xsl:choose> <xsl:when test ="date[not(.='')]"> date: <xsl:value-of select="events/event/date"><span class="ArrowLeft">></span> </xsl:when > <xsl:when test ="time[not(.='')]"> time: <xsl:value-of select="events/event/time"><span class="ArrowLeft">></span> </xsl:when> <xsl:when test ="location[not(.='')]"> location: <xsl:value-of select="events/event/location"><span class="ArrowLeft">></span> </xsl:when> <xsl:otherwise> #&160; </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:choose> <xsl:when test ="date[not(.='')]"> date: <xsl:value-of select="events/event/date"><span class="ArrowRight">></span> </xsl:when > <xsl:when test ="time[not(.='')]"> time: <xsl:value-of select="events/event/time"><span class="ArrowRight">></span> </xsl:when> <xsl:when test ="location[not(.='')]"> location: <xsl:value-of select="events/event/location"><span class="ArrowRight">></span> </xsl:when> <xsl:otherwise> #&160; </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </a> </td> </xsl:for-each> </tr></table> It can probably be done with XSLT, but I'm not completely sure what's the desired format you're looking for. Maybe seeing your XSLT will help. The desired format is represented by the second code block in my original post (not really code, but the code block retains spaces). What this code generates is the undesired result represented by code block 1 Link to comment Share on other sites More sharing options...
boen_robot Posted November 3, 2010 Share Posted November 3, 2010 I saw how your table looked in relation to the sample... but I don't understand how should the output look in other XML files.Let me try to see if I've got the idea right... a column for each event... first row is corresponding date, second row is corresponding location? I'm guessing you've limited yourself to the first 3 to show only the most recently added ones (which you've made a policy to add at the top I hope)? <table id="tblEvents"> <tr> <xsl:for-each select ="event[position() < 3]"> <th> <xsl:value-of select ="name" /> </th> </xsl:for-each> </tr> <tr> <xsl:for-each select ="event[position() < 3]"> <td> <xsl:value-of select="date" /> </td> </xsl:for-each> </tr> <tr> <xsl:for-each select ="event[position() < 3]"> <td> <xsl:value-of select="location" /> </td> </xsl:for-each> </tr></table> There's probably a more elegant way of doing it, but I can't think of any from the top of my head. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.