Subject: Re: [xsl] creating nodes from text From: omprakash.v@xxxxxxxxxxxxx Date: Wed, 6 Apr 2005 18:14:33 +0530 |
Hi Dave, Your comments were: 1) <xsl:if test="*[1][name() = 'a'] and not(. = '')"> better to use slf::a rather than name()='a' Thanks. I have made this change. 2) <xsl:variable name="elemname" select="normalize-space(text())"/> You could add <xsl:strip-space elements="*"/> to ignore white space text nodes, or ignore it explictly here with something like normalize-space(text()[normalize-space()])" I have done the former 3) <xsl:for-each select="../*[2][name() = 'td']/*[1]/*[1]"> This is a very odd expression. Maybe. But you haven't said that it is wrong. 4) It's equivalent to preceding-sibling::*[last()-1][self::td]/*[1]/*[1]" This for-each is only going to sleect one node because of the numeric filters, it isn't going to select all the attribute rows, which would be preceding-sibling::*[last()-1][self::td]/table/tr" I have made this change too. Doesn't preceding-sibling::* refer to all nodes occurring before current node ( td in my case) in document order and I don't have any. Could I use following-sibling::* as well. 5) This variable is not used at all you could use it or use *[2] inline, I have corrected this error. 6) <xsl:variable name="elemname" select="normalize-space(text())"/> You don't need this variable (but if you find it's easier to maintain, If I do that Iam getting this error: You cannot call an element 'normalize-space(text())' 7) The error I mentioned "Attribute '{$attrname}' outside of element" hasn't gone away. 8) This for-each is only going to sleect one node because of the numeric filters, it isn't going to select all the attribute rows Thanks. I didn't mean to have the second numeric specifier in ../*[2][name () = 'td']/*[1]/*[1]. But the errors I got made to lose track. Is this somehow related to the above xpath not working if I used absolute names as follows: ../*[2][name() = 'td']/table/tr Sorry for the long mail. Appreciate your reply. Cheers, Omprakash.V David Carlisle To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <davidc@xxxxx cc: (bcc: omprakash.v/Polaris) o.uk> Subject: Re: [xsl] creating nodes from text 04/06/2005 05:32 PM Please respond to xsl-list > I am getting the error "Attribute '{$attrname}' outside of element.". Actually the error is in the xsl:element earlier, but your processor must have silently recovered from that. <xsl:if test="*[1][name() = 'a'] and not(. = '')"> better to use slf::a rather than name()='a' <xsl:variable name="elemname" select="normalize-space(text())"/> You don't need this variable (but if you find it's easier to maintain, it's OK to do so) You could just use the expression directly in the next line. However this is not the expression that you want to use. text() selects all the text nodes, there are two in this case, the first is a newline character coming before the a element, the second is "slideshow newline" normalize-space will just take the first node in document order which means it will normalize the newline to the empty string and then you will try to generate an element with name "". You could add <xsl:strip-space elements="*"/> to ignore white space text nodes, or ignore it explictly here with something like normalize-space(text()[normalize-space()])" <xsl:element name="{$elemname}"> <xsl:for-each select="../*[2][name() = 'td']/*[1]/*[1]"> This is a very odd expression. The current node is a td and then you go up and select the second child of your parent (if that's a td). and then selects its first grandchild. It's equivalent to preceding-sibling::*[last()-1][self::td]/*[1]/*[1]" This for-each is only going to sleect one node because of the numeric filters, it isn't going to select all the attribute rows, which would be preceding-sibling::*[last()-1][self::td]/table/tr" <xsl:variable name="attrname" select="*[1]"/> again you could inline this into teh expression below, or not, it's just a matter of personal taste. <xsl:variable name="attrval" select="*[2]"/> This variable is not used at all you could use it or use *[2] inline, although you appear to have used td[1] instead which will give you the attribute name again. <xsl:attribute name="{$attrname}"> <xsl:value-of select="td[1]"/> </xsl:attribute> </xsl:for-each> </xsl:element> 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 ________________________________________________________________________ This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited. Visit Us at http://www.polaris.co.in
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] creating nodes from text, David Carlisle | Thread | Re: [xsl] creating nodes from text, David Carlisle |
RE: [xsl] help with java.lang.outof, Nicola Harlow | Date | [xsl] (Block) Scripting code not wo, Kevin Doran |
Month |