Subject: Re: [xsl] XSLT2 variables / nodesets and their namespace From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 21 Jan 2005 12:52:34 GMT |
> Initially I added the namespace to the <html> tag in my output. That's > what created all the xmlns=""s. It seems everyone is talking about tags this morning. XSLT doesn't deel with tags and it is that difference that is leading to the confusion. If you just put a namespace declaration in the html start tag at the point that you generate the html element in the result then that will generate an html element in the xhtml namespace. Also xhtml will be the default namespace for any other elements that are within that element _in the stylesheet_ so if you just have <xsl:apply-templates/> there no other elements will be in the xhtml namespace and so if you generate head and body in no-namespace teh system will have to add xmlns="" when writing out a file to ensure they stay in no-namespace. The solution is to put xmlns="xhtml namespace" on the xsl:stylesheet element so that it is in scope for the whole stylesheet. <xsl:for-each select="$links/ul/li"> That selects li elements in no-namespace unless you have changed the default xpath namespace, and so if xhtml is the default for the whole stylesheet it will select nothing as <xsl:variable name="links"> <ul> <xsl:for-each select="/root/page"> <li> will have generated ul and li elements in the xhtml namespace. Conversely, if you have changed the default xpath namespace to xhtml, <xsl:for-each select="$links/ul/li"> would select xhtml li elements but there may not be any as now in: <xsl:variable name="links"> <ul> <xsl:for-each select="/root/page"> <li> /root/page is selecting an element called root in the xhtml namespace and a child called page in teh xhtml namespace. Almost certainly your input document has no such elements, so the for-each will be over an empty list and generate no li elements. You will need to switch the xpath default namespace back by adding a xpath-default-namespace="" on the for-each. It's probably simpler to forget aboout xpath-default-namespace and work as in XSLT1 and always explictly prefic all element names in XPath when they refer to an element in a namespace. David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT2 variables / nodeset, Tom Schutzer-Weissma | Thread | Re: [xsl] XSLT2 variables / nodeset, David Carlisle |
Re: [xsl] XSLT2 variables / nodeset, Tom Schutzer-Weissma | Date | RE: [xsl] Look ahead in xslt, Michael Kay |
Month |