[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: using xsl:with-param in apply-templates problem
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|