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

Re: How can I avaliate an expression XPath in a variab

Subject: Re: How can I avaliate an expression XPath in a variable
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 23 Oct 2002 11:25:10 +0100
xsl value of select translate
Hi Giovani,

> I've a problem when I try to avaliate the value of a variable that
> contain an expression XPath, as below:
>
> The XML file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <di>
>   <nome>Departamento de Informatica</nome>
>   <docentes>
>     <prof>Pedro Silva</prof>
>     <prof>Jorge Santos</prof>
>     <prof>Paulo Camargo</prof>
>   </docentes>
> </di>
>
> The stylesheet:
>
> <xsl:for-each select="/di/docentes/prof">
>   <xsl:element name="profRef">
>     <xsl:attribute name="href">
>       <xsl:variable name="pos" select="concat('/di/docentes/prof', '[',
> position(), ']')"/>
>       #<xsl:value-of select="translate($pos, ' ', '-')"/>
>     </xsl:attribute>
>   </xsl:element>
> </xsl:for-each>

You're making things far more complicated than they need to be. Within
the xsl:for-each, the current node is the prof element that you're
currently processing. To get the value of that prof element, all you
have to do is use the path:

  .

So try:
  
  <xsl:for-each select="/di/docentes/prof">
    <xsl:element name="profRef">
      <xsl:attribute name="href">
        <xsl:text />#<xsl:value-of select="translate(., ' ', '-')" />
      </xsl:attribute>
    </xsl:element>
  </xsl:for-each>

  
In fact, here you can make things even simpler by using an attribute
value template for the href attribute:

  <xsl:for-each select="/di/docentes/prof">
    <profRef href="#{translate(., ' ', '-')}" />
  </xsl:for-each>

(BTW, you can't take a string and treat it like an XPath expression.
If you want to evaluate a string as an XPath expression, then you have
to use an extension function such as dyn:evaluate() from EXSLT.)
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.