XSL Issue
This is an open discussion with 3 replies, filed under XSLT.
Search
Which bit isn't working exactly? The only thing that might be causing issue is the use of .
in your very final expression. You could try replacing it with current()
. I can never remember when to use which, since there are subtle differences between the two.
Anyway, I copied your XML into a Symphony Static Data Source and got this XSLT working.
<xsl:template match="/"> <xsl:apply-templates select="//page-layout/record[type='data-list']" mode="table"/> </xsl:template> <xsl:template match="record" mode="table"> <table> <thead> <xsl:apply-templates select="content/headers/record" mode="header"/> </thead> <tbody> <xsl:apply-templates select="content/data/record" mode="row"/> </tbody> </table> </xsl:template> <xsl:template match="record" mode="header"> <th><xsl:apply-templates select="name"/></th> </xsl:template> <xsl:template match="record" mode="row"> <xsl:variable name="row-data" select="."/> <tr> <xsl:for-each select="//content/headers/record/column"> <td><xsl:value-of select="$row-data/*[name()=current()]"/></td> </xsl:for-each> </tr> </xsl:template>
I simplified things somewhat by recognising patterns in the original XML. Each table, header and body row are record
nodes, so the templates to create each of these matches simply on a record. A mode is passed to each to ensure the correct one is used. I'm starting to use this approach more often — make matched templates very generic using modes, but make the apply-templates calling them very specific. This way, the more generic templates can be re-used (e.g. you can re-use the heading template anywhere else providing you have a record
node in your XML).
Thanks Nick,
I knew this was the right place to come, the secret key was current(), I too mix the two and with all of the things I've been working on today I just couldn't get passed that brick wall. This works wonders, and your idea with the modes simplifies things immensely! Thanks Tons!
Nick
No worries, glad it's sorted.
A couple of references I have bookmarked but always fail to return to:
http://www.devguru.com/Technologies/XSLT/quickref/xslt_function_current.html http://www.stylusstudio.com/docs/v60/d_xpath78.html
Create an account or sign in to comment.
This is not directly related to symphony but this is one of the better venues for finding XSL help that I know of. To start with I have some XML that looks like this:
and what I am wanting to do is use the
//page-layout/*/content/headers/*/column
to designate how to create my table of data. Right now there is only one record in the//page-layout/*/content/data
node set but the idea is to have all the data for thatdata-list
in that node set.right now my xsl looks like this:
The last template is what I'm having issues with. Any help would be appreciated :)