Subject: [xsl] problem with Passing Parameters to Templates From: Helen_Li@xxxxxxx Date: Fri, 19 Jan 2001 10:04:57 -0500 |
Hi Folks, I am a novice at XSL and have a problem with passing parameters to templates. In the following xsl file, I defined a named template 'opt_template', in which what I want to do is to simply output the paramete value(i.e. $node) and value of the 'text_node' if the node(passed thru parameter) exists. <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> . . . <xsl:call-template name="opt_template"> <xsl:with-param name="node">text_node</xsl:with-param> </xsl:call-template> <xsl:template name="opt_template"> <xsl:param name="node"></xsl:param> <xsl:text>$node</xsl:text> ------ Is this the right way to output parameter value? <xsl:if test="//*[$node]"> <xsl:value-of select=".//$node"/> --------------expected node test??? </xsl:if> <xsl:call-template name="Print_Comma_Separator"/> </xsl:template> . . . </xsl:stylesheet> I can not even get it run successfully. It complained "expected node test" on line <xsl:value-of select=".//$node"/>. Does anybody know what I did wrongly? Thanks, Helen mail@xxxxxxxxxxxxxxxx on 18/01/2001 11:27:37 AM Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: Helen Li/Net@Saville cc: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] template pattern does not get matched properly with xmlns declaration Hi Helen, > However after I removed xmlns declaration(i.e xmlns=" > http://www.ipdr.org/namespaces/ipdr" part) from IPDRDoc element > in test.xml, everything is just working fine. I have no idea what's wrong with > the xml/xsl test files. The fact that taking the default namespace declaration out changed things indicates that it's a namespace issue. Because of the default namespace declaration, all the elements that don't have a prefix are placed in the 'http://www.ipdr.org/namespaces/ipdr' (IPDR) namespace. Now, in your stylesheet you match against IPDRDoc elements but don't specify a prefix for them. If you don't specify a prefix when you're matching/selecting an element, then it assumes you mean an element in the *null* namespace. The IPDRDoc element in the IPDR namespace isn't an IPDRDoc element in the null namespace, so it doesn't match that template, and the built in templates are used all the way through. To get around this, you need to declare the IPDR namespace (with a prefix) within the XSLT stylesheet. Something like: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ipdr="http://www.ipdr.org/namespaces/ipdr"> ... </xsl:stylesheet> Then, whenever you want to refer to an element in that namespace, you have to use the prefix you've assigned to it (ipdr in this case) within the name. For example, the match pattern for the template should be: <xsl:template match="ipdr:IPDRDoc"> ... </xsl:template> By the way, space is preserved within all elements in your source by default, so: <xsl:preserve-space elements="text" /> won't have any effect unless you also tell it to strip spaces for the 'text' element, perhaps by telling it to strip spaces for *all* elements through something like: <xsl:strip-space elements="*" /> I don't see any 'text' elements in your source, though, so I'm not exactly sure why you've got this instruction in the first place? I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list ******************** The information contained in this e-mail is confidential and intended solely for the use of the addressee(s) listed above. If you have obtained this message in error or otherwise, please notify the sender and destroy all copies of this message immediately. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Reading XSLT results into, Hahn, Kimberly | Thread | Re: [xsl] problem with Passing Para, David Carlisle |
Re: [xsl] Reading XSLT results into, David Carlisle | Date | RE: [xsl] Reading XSLT results into, Wendell Piez |
Month |