xsl-list
[Top] [All Lists]

Re: [xsl] XPath behaviour

2006-12-28 08:12:53
Lars,

It could be that the query editor supports XPath 2.0, or if not some extended variant of XPath. Your expression looks okay in XPath 2.0 but not in XPath 1.0 (a considerably more limited expression language), hence the error.

Unfortunately, the limitation here is that you can't group a step in XPath 1.0 -- although you can (thankfully) use a predicate (the bracketed expression) on a group. So your only choices are (1) to expand your XPath, (2) to refactor it (the XPath or, sometimes better, the data), or (3) to break it out using variables (or some combination of these).

I'd probably do something like this:

<xsl:variable name="the-day"
  select="/calendar/year/month/day[(_at_)month = 3 and index = 21]"/>

<xsl:variable name="first-phase2-day"
  select="($the-day | $the-day/following-sibling::day)[(_at_)phase = 2][1]"/>

<xsl:variable name="first-phase2-day6"
  select="($first-phase2-day | $first-phase2-day/following-sibling::day)
          [(_at_)weekday = 6][1]"/>

Note: I've used the following-sibling:: axis. I'm guessing that your use of the following:: axis is a bug waiting to happen (although without seeing your data I can't say for sure). Please check the difference and use the better choice (perhaps keeping in mind that the following:: axis will look all the way forward through the document, and thus may cost microseconds even when it isn't just wrong).

I hope this helps.

Cheers,
Wendell

At 09:10 PM 12/27/2006, you wrote:
Dear list,

I am having a problem with an XPath expression. The program I am using is
Stylus Studio 2007 and I am building an XSLT 1.0 stylesheet. Within the
program you have access to an XPath Query Editor. I used that together
with an XML file to build the following:

/calendar/year/month/day[(_at_)month = 3 and index =
21]/(.|following::day)[(_at_)phase = 2][1]/(.|following::day)[(_at_)weekday = 
6][1]

This path will correctly find easter when I execute it in the query
editor. However, if I create a simple stylesheet that uses the path in a
<xsl:value-of select="..."> I get a compilation error.

Using the built-in processor I get the message:
Testing.xsl (5, 2): Expected node test in value-of

Using MSXML6 I get the message:
NodeTest expected here.

/calendar/year/month/day[(_at_)month = 3 and index =
21]/-->(<--.|following::day)[(_at_)phase = 
2][1]/(.|following::day)[(_at_)weekday =
6][1]

Using Saxon 6.5.5 I get the message:
com.icl.saxon.expr.XPathException: Error in expression
/calendar/year/month/day[(_at_)month = 3 and index =
21]/(.|following::day)[(_at_)phase = 2][1]/(.|following::day)[(_at_)weekday = 
6][1]:
Unexpected token [(] in path expression

Using the .NET XslTransform I get the message:
System.Xml.Xsl.XsltException: '/calendar/year/month/day[(_at_)month = 3 and
index = 21]/(.|following::day)[(_at_)phase = 
2][1]/(.|following::day)[(_at_)weekday
= 6][1]' is an invalid XPath expression. --->
System.Xml.XPath.XPathException: Expression must evaluate to a node-set.

>From this I gather that it doesn't like the parenthesis. However, if I
remove them I do not get the desired behaviour. Instead, three days are
matched and none of them correctly.

How am I supposed to group the union in such a way that I can apply the
subset rules (within brackets) to it? It would also be interesting to know
why this works in the query editor, but none of the processors.

Any help is appreciated,
Regards,
Lars Rönnbäck


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>