[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: problem with variable and position()

Subject: RE: problem with variable and position()
From: fe.sola@xxxxxxxxxxxxxx
Date: Wed, 27 Aug 2003 17:42:56 -0400
xsl variable position
Hello Jarno and Michael, thanks for your quick response.
I still have troubles with this template, I realized I can't use a variable on a match 
expression and it is a bad practice to use a global one, re-wrote the template but still 
no good.
The input xhtml documet has several text nodes, one of them starts with the 
word "Description", I should be able to select all the text nodes that have a position 
higher than that one and put it on a single description element.
The templates I rewrote are:
<xsl:template match="body">
     <!-- some templates here for the rest of the text nodes-->
     <xsl:element name="description">
                       <xsl:apply-templates select="text()[starts-with(normalize-space
(),'Description')]"/>
     </xsl:element>
</xsl:template>
<xsl:template match="text()[starts-with(normalize-space(),'Description')]">
                   <xsl:variable name="descPos" select="position()"/> 
                   <xsl:apply-templates select="text()[position()>$descPos]"/> 
</xsl:template>   and hoped the built in templates would work but the <description> tag 
won't get any value after the transformation...
tia, lizet

Mensaje citado por Jarno.Elovirta@xxxxxxxxx:

> Hi,
> 
> > <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>
> 
> This template could as well be simply
> 
>   <xsl:template match="text()" mode="description">
>     <xsl:variable name="descPos" select="position()"/>
>     <xsl:apply-templates select="text()[position()>$descPos]"/>
>   </xsl:template>
> 
> unless you have multiple different templates that match text nodes in "description"
> mode.
> 
> > <xsl:template match="text()[position()>$descPos]">
> >                               <xsl:value-of select="."/>
> > </xsl:template>  
> 
> And this should be
> 
>   <xsl:template match="text()">
>     <xsl:value-of select="."/>
>   </xsl:template>
> 
> or, you don't even need this, because the build-in template rule will take care of it
>   
> > 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? 
> 
> For one, the descPos variable will be out of scope in the other template -- see the
> XSLT spec for variable scope. Also, variable references are not allowed in match
> patterns.
> 
> Cheers,
> 
> Jarno
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 




-------------------------------------------------
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.