Re: [xsl] Getting the value of previous Sibling

Subject: Re: [xsl] Getting the value of previous Sibling
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 14 Jul 2004 13:01:04 +0100
       <xsl:template match="//input">

You never want to start a match pattern with // (it doesn't do anything
useful) just use   <xsl:template match="input">

       <xsl:if test="@type='radio'">

This xsl:if isn't closed anywhere so your template is not well formed
XML you need an </xsl:if> as the last line of the template

       <xsl:copy>
            <xsl:variable name="name"><xsl:value-of
       select="preceding-sibling::element[position()=1]/@name"
       /></xsl:variable>

You don't really need a variable at all here, but if you did, it's
almost always better to go
            <xsl:variable name="name"
       select="preceding-sibling::element[position()=1]/@name"
       />
as that makes the value of the variable  the node itself which is
lot nore efficient than the version you have which makes the value of
the variable a result tree fragment consisting of a root node cwith
child a text node with vstring value the string value of the node you
wanted.


            <xsl:variable name="value"><xsl:value-of
       select="preceding-sibling::element[position()=1]/@value"
       /></xsl:variable> 

same comment as above.
   	
       	<xsl:apply-templates select="@*"/>

This may or may not be OK, depending on what template you have defined
for attribute nodes. By default this will just produce the
values of the attributes as element content and lose the attribute
names. If you have defined a template for attributes that copies
the attributes this will copy the attributes, but that can more simply
be done by <xsl:copy-of select=""@*"/>


           <xsl:attribute name="onclick">$name,$value</xsl:attribute>
That will make onklick="$name,$value" as the $varname syntax only means
something in an XPath expression, not as content of an XSL element.
You would need
<xsl:attribute name="onclick"><xsl:value-of select="concat($name,$value)"/></xsl:attribute>
But as mentioned above you don't really need the variables, you could
just do
<xsl:attribute name="onclick"><xsl:value-of select="concat(
  preceding-sibling::element[1]/@name,
  preceding-sibling::element[1]/@value
  )"/></xsl:attribute>
          <xsl:apply-templates select="*|text()"/>
       
       </xsl:copy>
and you need an </xsl:if> here
       </xsl:template>

David
`

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. 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