You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Yann <yl...@ims.ltd.uk> on 2000/04/26 16:54:02 UTC

XSL variable name usage

Sorry if this is not that Cocoon related, but I am stuck and I have tight
deadlines to demonstrate my Coccon project.

In my XSL document, I want to compare the value of a temporary XSL variable
with an element attribute from my XML document (an item element) so that I
can decide which item to be the selected value in a combobox:

<xsl:template match="Combobox">
  <select name="combovalue" >
   <xsl:variable name="selecteditem" select="@selected" />
   <xsl:apply-templates />
  </select>
 </xsl:template>

<xsl:template match="Item">
  <xsl:element name="option">
   <xsl:if test="itemcode=$selecteditem">
    <xsl:attribute name="selected">true</xsl:attribute>
   </xsl:if>
   <xsl:attribute name="value"><xsl:value-of select="itemcode"
/></xsl:attribute>
   <xsl:value-of select="itemstring" />
  </xsl:element>
 </xsl:template>

I get:

org.apache.xalan.xslt.XSLProcessorException: pattern =
'itemcode=$selecteditem'
VariableReference given for variable out of context or without definition!
Name = selecteditem

It's not very difficult what I want to do (have a temporary variable to use
in another template). I imagined it would be visible from children nodes
though.

Thanks for your help,

Yann, nearly finishing his first Cocoon-based web-app.



Re: XSL variable name usage

Posted by Sonja Loehr <11...@onlinehome.de>.

Yann schrieb:

> In my XSL document, I want to compare the value of a temporary XSL variable
> with an element attribute from my XML document (an item element) so that I
> can decide which item to be the selected value in a combobox:
>
> <xsl:template match="Combobox">
>   <select name="combovalue" >
>    <xsl:variable name="selecteditem" select="@selected" />
>    <xsl:apply-templates />
>   </select>
>  </xsl:template>
>
> <xsl:template match="Item">
>   <xsl:element name="option">
>    <xsl:if test="itemcode=$selecteditem">
>     <xsl:attribute name="selected">true</xsl:attribute>
>    </xsl:if>
>    <xsl:attribute name="value"><xsl:value-of select="itemcode"
> /></xsl:attribute>
>    <xsl:value-of select="itemstring" />
>   </xsl:element>
>  </xsl:template>
>
> I get:
>
> org.apache.xalan.xslt.XSLProcessorException: pattern =
> 'itemcode=$selecteditem'

> VariableReference given for variable out of context or without definition!
> Name = selecteditem
>

Later he wrote he had found another solution, whithout
variables, I guess.
There were still other messages concerning the "$",
but I'm not sure whether the WAP-problem with the "$" has
anything to do with my case, which is just <xsl:variable> in a
stylesheet for conversion to
HTML (I'm a bit confused about the suggested solutions).
Therefore I'd like to refresh this question because
I've got the very same problem in a much simpler context. I
want to do something like

<xsl:for-each select="XYZ">
<xsl:if test="string(.)='$deepest'">............</xsl:if>
.....
</xsl:for-each>


and I tried hundreds of alternatives, using curly braces,
round braces and so on, but everything containing the
"$"-character was rejected. Unfortunately, I can't see an
alternative way for my task, you?

I have to sort elements in order to get the most deeply
embedded one. That one shall be displayed - say - blue. 
I want to display all these elements, but in NORMAL order
(that one before sorting)!! That is, the sorting is
good for nothing but finding the one to be styled - blue.
Because the very same elements are affected, I always get
either the "normal order" (with nothing blue) or the sorted
elements with the blue one. Therefore I wanted to use that
variable to store the deepest element.

Any solution for the variable-problem or another way solving
the sorted-unsorted conflict?
  

Good luck

Sonja



> ------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

Re: XSL variable name usage

Posted by Yann <yl...@ims.ltd.uk>.
> In my XSL document, I want to compare the value of a temporary XSL
variable
> with an element attribute from my XML document (an item element) so that I
> can decide which item to be the selected value in a combobox:

Don't worry about it. I found a much much simple way, i.e. accessing the
parent attribute value using "../" instead of storing it.

Yann.