Subject: RE: [xsl] Parameter passing through call to "document" From: cknell@xxxxxxxxxx Date: Thu, 16 Mar 2006 21:26:04 -0500 |
You have a template that matches "/projects". In this template you do an apply-templates and attempt to pass a parameter named "project_id". The value you assign to this parameter appears to be a node named "record_id_". There is your problem. This construct assumes an XPath structure of "/projects/record_id_", where in the actual document the XPath is "/projects/record/record_id_". When you assign "/projects/record_id_" to the value of the parameter, you are selecting a node that doesn't exist. Ergo, you get the default value of the parameter. -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: William Scarvie <wscarvie@xxxxxxxxxxx> Sent: Thu, 16 Mar 2006 16:00:25 -0800 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Parameter passing through call to "document" Hi all, I'm trying to use xsl:apply-templates, selecting an external document, and using xsl:with-param to pass a parameter to the template that will handle the incoming document. For some reason, the value passed in the parameter never makes it to the template. Instead, I get the default value. If I do a test changing the select of the xsl:apply-templates call such that I'm passing in children of the current context, the value passes into the template just fine. I know the "document" call is working correctly, and the tasks template is being called, because if I take out the xsl:if test, I get all records to show up under each project. I've appended sample code to show you what I'm up to. Generally, I have one file containing projects, and another containing tasks. There is a 1:many relationship between projects:tasks, identified by the contents of the "record_id_" tag in the Projects XML and the "related_project" tag in the Tasks XML. When the values match, the task is related to the project. I'm trying to emit a table that shows, for each project, a list of all tasks associated with the project. Thanks very much in advance. Any help with what I'm doing wrong here, or suggestions for other ways to accomplish what I'm after, would be most appreciated. Thanks again, Will Scarvie ----- Project.xml ----- <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="Project.xsl" ?> <projects> <record> <project_family>Backlog</project_family> <priority>1</priority> <description>Highest Priority Backlog Project</description> <record_id_>4</record_id_> </record> <record> <project_family>Backlog</project_family> <priority>2</priority> <description>Lowest Priority Backlog Project</description> <record_id_>1</record_id_> </record> <record> <project_family>Next Year</project_family> <priority>2</priority> <description>Lowest Priority New Project</description> <record_id_>3</record_id_> </record> <record> <project_family>Next Year</project_family> <priority>1</priority> <description>Highest Priority New Project</description> <record_id_>2</record_id_> </record> </projects> ----- Tasks.xml ----- <?xml version="1.0" ?> <tasks> <record> <rank>1</rank> <description>Task One</description> <related_project>4</related_project> <record_id_>114</record_id_> </record> <record> <rank>4</rank> <description>Task Four</description> <related_project>4</related_project> <record_id_>114</record_id_> </record> <record> <rank>3</rank> <description>Task Three</description> <related_project>3</related_project> <record_id_>114</record_id_> </record> <record> <rank>2</rank> <description>Task Two</description> <related_project>3</related_project> <record_id_>114</record_id_> </record> </tasks> ----- Project.xsl ----- <xsl:stylesheet version="1.0" xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/projects"> <html> <body> <table border="1" width="100%" cellpadding="5"> <tr> <th>Family</th> <th>Priority</th> <th>Description</th> </tr> <xsl:for-each select="record"> <xsl:sort data-type="text" select="project_family"/> <xsl:sort data-type="number" select="priority"/> <tr> <td> <xsl:value-of select="project_family"/> </td> <td> <xsl:value-of select="priority"/> </td> <td> <xsl:value-of select="description"/> </td> </tr> <tr> <td> </td> <td colspan="2"> About to call apply-templates, with project_id of <xsl:value-of select="record_id_"/> <xsl:apply-templates select="document('Tasks.xml')"> <xsl:with-param name="project_id" select="record_id_"/> </xsl:apply-templates> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="/tasks"> <xsl:param name="project_id" select="'undefined'"/> Entering Tasks template<BR/> Project ID parameter is: <xsl:value-of select="$project_id"/><BR/> <xsl:for-each select="record"> <xsl:sort data-type="number" select="rank"/> <xsl:if test="related_project = $project_id"> Task: <xsl:value-of select="description"/><BR/> Rank: <xsl:value-of select="rank"/><BR/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Parameter passing through, Florent Georges | Thread | RE: [xsl] Parameter passing through, William Scarvie |
Re: Re: [xsl] Complex expression, Oleg Konovalov | Date | RE: [xsl] Parameter passing through, William Scarvie |
Month |