|
Subject: RE: [xsl] problem with variable and position() From: "Michael Kay" <mhk@xxxxxxxxx> Date: Wed, 27 Aug 2003 12:15:37 +0100 |
You can't define a match pattern that uses a variable.
In 1.0 you have to test the variable inside the template, e.g
<xsl:template match="text()">
<xsl:choose>
<xsl:when test="count(preceding::text() > $pos)">
Of course the variable must be global.
2.0 does allow a global variable to be used in the pattern.
A better solution in 2.0 is to use the ">>" operator:
<xsl:key name="t" match="text()[startswith(., 'Description')]"
use="'z'"/>
<xsl:template match="text()[. >> key('t', 'z')]
I can't see an easy way to emulate this in 1.0 with a solution that's
likely to have less than O(n^2) performance.
Michael Kay
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> fe.sola@xxxxxxxxxxxxxx
> Sent: 27 August 2003 07:31
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] problem with variable and position()
>
>
> This is part of the stylesheet...
>
>
> <xsl:template match="html">
> <xsl:apply-templates select="head"/>
> <xsl:apply-templates select="body"/>
> </xsl:template>
>
>
> <xsl:template match="head"/>
> <xsl:template match="body">
> <xsl:element name="description">
> <xsl:apply-templates
> select="text()[starts-with(normalize-space
> (),'Description')]" mode="description"/>
> </xsl:element>
> </xsl:template>
> <xsl:template
> match="text()[starts-with(normalize-space(),'Description')]"
> mode="description">
> <xsl:variable name="descPos"
> select="position()"/>
> <xsl:apply-templates
> select="text()[position()>$descPos]"/>
>
> </xsl:template>
> <xsl:template match="text()[position()>$descPos]">
> <xsl:value-of select="."/>
> </xsl:template>
>
> I have an xhtml document with a description as a text element
> in the body. This
> description text start with the word "Description" and it has
> a variable position inside
> the input documents. I tried to store the position of the
> description text in the
> descPos variable to use it later, but the above stylesheet
> gives me an error of "Invalid
> variable reference". How could I re-write the last template
> so I avoid this error?
> tia,
> lizet
>
> -------------------------------------------------
> Este mensaje fue enviado usando el servicio de correo en web
> de Infomed http://webmail.sld.cu
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] problem with variable and pos, fe . sola | Thread | RE: [xsl] global variable and posit, fe . sola |
| RE: [xsl] how many TraX-XSLT-proces, Michael Kay | Date | RE: [xsl] recursion with xsl:apply-, Michael Kay |
| Month |