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

RE: Recursive evaluation of expressions

Subject: RE: Recursive evaluation of expressions
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 19 Dec 2009 10:46:55 -0000
RE:  Recursive evaluation of expressions
You're asking it to output the result of concat($p1/../caption, ' ',
$p1/description), and that's what it's doing. If you want to treat
caption/eval as an expression and evaluate it, rather than outputting its
string value, then you will have to ask for that by another call on
saxon:evaluate().

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> -----Original Message-----
> From: Rowan Sylvester-Bradley [mailto:rowan@xxxxxxxxxxxxxxxxxxxxx] 
> Sent: 19 December 2009 01:18
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Recursive evaluation of expressions
> 
> I'm still struggling to get this working. I need to be able 
> to evaluate XPath expressions in my input XML document. This 
> works OK, but I also need to be able to refer in an XPath 
> expression to an element that contains another expression, 
> and to pick up the result of evaluating the second 
> expression, not just the text of the expression.
> Here's a sample input document:
> <items>
>    <item>
>       <id>a</id>
>       <caption>Sandwich Meal</caption>
>       <item>
>          <id>a1</id>
>          <description>White roll</description>
>          <caption><eval>concat($p1/../caption, ' ', 
> $p1/description)</eval></caption>
>          <item>
>             <id>a1a</id>
>             <description>Chicken</description>
>             <caption><eval>concat($p1/../caption, ' ', 
> $p1/description)</eval></caption>
>          </item>
>          <item>
>             <id>a1b</id>
>             <description>Ham</description>
>             <caption><eval>concat($p1/../caption, ' ', 
> $p1/description)</eval></caption>
>          </item>
>       </item> 
>    </item>    
> </items>                 
> 
> And here's a simplified version of my stylesheet:
> <xsl:stylesheet version="2.0" 
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    xmlns:saxon="http://saxon.sf.net/"
>    exclude-result-prefixes="xs saxon">
> 
>    <xsl:strip-space elements="*"/>
>    <xsl:output indent="yes"/>
>    
>    <xsl:template match="node()|@*">
>       <xsl:copy>
>          <xsl:apply-templates select="node()|@*"/>
>       </xsl:copy>
>    </xsl:template>  
>    
>    <xsl:template match="item">
>       <item>
>          <xsl:apply-templates>
>             <xsl:with-param name="source" select="." tunnel="yes"/>
>          </xsl:apply-templates>   
>       </item>
>    </xsl:template>
>    
>    <xsl:template match="eval">
>       <xsl:param name="source" tunnel="yes"/>
>       <xsl:value-of select="saxon:eval(saxon:expression(.), 
> $source)"/>
>    </xsl:template>   
> 
> </xsl:stylesheet>  
> 
> This produces the following:
> <?xml version="1.0" encoding="UTF-8"?>
> <items>
>    <item>
>       <id>a</id>
>       <caption>Sandwich Meal</caption>
>       <item>
>          <id>a1</id>
>          <description>White roll</description>
>          <caption>Sandwich Meal White roll</caption>
>          <item>
>             <id>a1a</id>
>             <description>Chicken</description>
>             <caption>concat($p1/../caption, ' ', 
> $p1/description) Chicken</caption>
>          </item>
>          <item>
>             <id>a1b</id>
>             <description>Ham</description>
>             <caption>concat($p1/../caption, ' ', 
> $p1/description) Ham</caption>
>          </item>
>       </item>
>    </item>
> </items>
> 
> What I want instead of              
>             <caption>concat($p1/../caption, ' ', 
> $p1/description) Chicken</caption> is
>             <caption>Sandwich Meal White roll Chicken</caption>
> 
> How can I get it to do this?
> 
> Many thanks - Rowan

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.