Re: [xsl] creating nodes from text

Subject: Re: [xsl] creating nodes from text
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 6 Apr 2005 13:02:31 +0100
> 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
________________________________________________________________________

Current Thread