Subject: RE: [xsl] Recursive evaluation of expressions From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Sat, 19 Dec 2009 10:46:55 -0000 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Recursive evaluation of expre, Rowan Sylvester-Brad | Thread | [xsl] innermost enclosing element o, Piotr Dobrogost |
[xsl] Recursive evaluation of expre, Rowan Sylvester-Brad | Date | Re: [xsl] calling template with nam, Piotr Dobrogost |
Month |