Subject: [xsl] Is it possible to access a tag after using apply-templates? From: XemonerdX <xemonerdx@xxxxxxxxx> Date: Fri, 4 Jul 2008 15:56:16 +0200 |
Is the following possible? I can't seem to wrap my head around it, but I am an XSLT newbie, so that might explain it :) I have an XML file that contains data that needs to be displayed: <?xml version="1.0" ?> <top> <data> <title>title of page</title> <name>Your name</name> </data> <cells> <cell> <name>cell 1</name> <value>100</value> </cell> <cell> <name>cell 2</name> <value>200</value> </cell> <cell> <name>cell 3</name> <value>300</value> </cell> </cells> </top> I also have a layout XML file that will be used to put the data from the above XML-file into a certain layout, called layout.xml: <?xml version="1.0" encoding="utf-8"?> <layout> <layout-main> <html> <head> <title><insert-title/></title> </head> <body> <div> My name is: <insert-name/> </div> <div> <table> <insert-cells/> </table> </div> </body> </html> </layout-main> <layout-cell> <tr> <td><insert-cell-name/></td> <td><insert-cell-value/></td> </tr> </layout-cell> </layout> And then I have the XSL file to tie it all together (hopefully!): <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:variable name="data" select="/"/> <xsl:variable name="layout" select="document('http://localhost/webopac2/xml/datatemplate_layout.xml')"/> <xsl:template match="/"> <xsl:apply-templates select="$layout/layout/layout-main/*"/> </xsl:template> <!-- transformations --> <xsl:template match="insert-name"> <xsl:value-of select="$data/top/data/name"/> </xsl:template> <xsl:template match="insert-title"> <xsl:value-of select="$data/top/data/title"/> </xsl:template> <xsl:template match="insert-cells"> <xsl:for-each select="$data/top/cells/cell"> <xsl:variable name="name" select="name"/> <xsl:variable name="value" select="value/*"/> <xsl:apply-templates select="$layout/layout/layout-cell/tr"> <xsl:with-param name="name" select="$name"/> </xsl:apply-templates> <xsl:call-template name="insert-cell-name"> <xsl:with-param name="name" select="$name"/> </xsl:call-template> </xsl:for-each> </xsl:template> <xsl:template name="insert-cell-name"> <xsl:param name="name"/> <xsl:value-of select="$name"/> </xsl:template> <!-- Identity transformation --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> I would like the output to look like the following: <html> <head> <title>title of page</title> </head> <body> <div> My name is: Your name </div> <div> <table> <tr> <td>cell 1</td> <td>100</td> </tr> <tr> <td>cell 2</td> <td>200</td> </tr> <tr> <td>cell 3</td> <td>300</td> </tr> </table> </div> </body> </html> Unfortunately that's not quite the result. I can't seem to be able to replace the 'insert-cell-name' and 'insert-cell-value' tags with the corresponding 'name' and 'value' tag values. Is this possible? The reason I want to keep as much layout out of the XLS-file as possible is to allow non-developers to design a layout without knowing XSLT. This way I can hopefully also use a single XLS-file where 'layout.xml' can be easily changed/generated. Thanxxx for any guidance/advice/comments... Edwin
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Empty input in analyze-st, Mathieu Malaterre | Thread | Re: [xsl] Is it possible to access , Martin Honnen |
RE: [xsl] Empty input in analyze-st, Michael Kay | Date | Re: [xsl] Split with delimiter and , Florent Georges |
Month |