Subject: Re: [xsl] using xsl:with-param in apply-templates problem From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 27 Aug 2002 13:17:14 +0100 |
Hello Niki :) > David, thanks for your advice, I have change the SS accordingly, it > all seems to work apart from the param being passed: You're probably losing the parameter en-route from the document element of the document you're processing to the ATITLE, BTITLE etc. elements in the body of the document. The built-in template, used for the document element of that document, is: <xsl:template match="*" mode="file"> <xsl:apply-templates mode="file" /> </xsl:template> As you can see, the parameter doesn't get passed through this built-in template. So try overriding it so that the parameter gets passed through to the children of the element: <xsl:template match="*" mode="file"> <xsl:param name="filename" /> <xsl:apply-templates mode="file"> <xsl:with-param name="filename" select="$filename" /> </xsl:apply-templates> </xsl:template> [Note that in XSLT 2.0, parameters will get passed through by default so you won't have to worry about this.] Also note what David said about match patterns -- they never need to start with '//' -- //foo matches "foo elements that are descendants of the root node" but *all* foo elements must be descendants of a root node, so there's no point testing that. Your template: <xsl:template match="//ATITLE|//BTITLE|//CTITLE|//DTITLE|//ETITLE|//FTITLE" mode="file"> <xsl:param name="filename"/> <title> <xsl:attribute name="filename"> <xsl:value-of select="$filename"/> </xsl:attribute> <xsl:attribute name="chapID"> <xsl:value-of select="ancestor::*[last()]/attribute::ID"/> </xsl:attribute> ... </title> ... </xsl:template> would be better as: <xsl:template match="ATITLE|BTITLE|CTITLE|DTITLE|ETITLE|FTITLE" mode="file"> <xsl:param name="filename"/> <title filename="{$filename}" chapID="{/*/@ID}"> ... </title> ... </xsl:template> [I've also used attribute value templates here just 'cos they're shorter, and note that "ancestor::*[last()]/attribute::ID" is equivalent to "/*/@ID" -- the ID attribute of the document element. (Is that what you meant to do, or did you want "../@ID", the ID attribute of the element's parent?)] Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] using xsl:with-param in a, David Carlisle | Thread | Re: [xsl] using xsl:with-param in a, David Carlisle |
[xsl] html to xml, Alia Mikati | Date | [xsl] html to xml, Alia Mikati |
Month |