Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2011, 10:19 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Pattern syntax Error XTSE0340

I've got a weird situation that I can't seem to figure out. I'm trying to run a simple transformation on a xhtml document. I'm getting and error when I run it that states, " XTSE0340: XSLT Pattern syntax error at char 51 on line 12 in {...ors']/following-sibling::ta...}: Axis in pattern must be child or attribute" However, I've tested the XPath multiple times and everything looks good to me. It resolves on the document when I run it separately, but in the XSLT it fails. I'm running Saxon 8.9 using Stylus Studio, XSLT 2.0. I've tried it under a couple different processors, even 1.0 and still won't work. I cannot think of a reason why it would be requiring a child or attribute. What am I doing wrong?

The XPath in question that is failing is this.
Code:
font[descendant::text() = 'Consolidated Errors']/following-sibling::table[1]
The input document is as follows. (Sorry it's a bit long but I trimmed it down best I could)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <body>
        <table cellpadding="2" cellspacing="0" border="1" width="80%" align="center">
            <tr bgcolor="#C0C0C0">
                <td>
                    <font face="Geneva,Arial">
                        <b>Line of Business</b>
                    </font>
                </td>
                <td>
                    <font face="Geneva,Arial">
                        <b>Total # of Messages</b>
                    </font>
                </td>
                <td>
                    <font face="Geneva,Arial">
                        <b># of Passed Messages</b>
                    </font>
                </td>
                <td>
                    <font face="Geneva,Arial">
                        <b># of Failed Messages</b>
                    </font>
                </td>
                <td>
                    <font face="Geneva,Arial">
                        <b>Total # of Errors in Failed Messages</b>
                    </font>
                </td>
            </tr>
        </table>
        <table cellpadding="0" cellspacing="1" width="98%" align="center" bgcolor="#000000">
            <tr valign="top">
                <td>
                    <table cellpadding="2" cellspacing="0" width="100%" bgcolor="#C0C0C0">
                        <tr valign="top">
                            <td width="200">
                                <font face="Geneva,Arial" size="-1">
                                    <b>File (PolSymbol_SubmissionNo)</b>
                                </font>
                            </td>
                            <td width="40" align="right">
                                <font face="Geneva,Arial" size="-1">
                                    <b>Line</b>
                                </font>
                            </td>
                            <td width="40" align="right">
                                <font face="Geneva,Arial" size="-1">
                                    <b>Col</b>
                                </font>
                            </td>
                            <td>
                                <font face="Geneva,Arial" size="-1">
                                    <b>Error</b>
                                </font>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <font face="Geneva,Arial">
            <p align="center">
                <b>
                    <u>Consolidated Errors</u>
                </b>
            </p>
        </font>
        <table cellpadding="0" cellspacing="1" width="98%" align="center" class="nested">
            <th valign="top" colspan="4" align="left">
                <font face="Geneva,Arial" size="3">Farm General Liability</font>
            </th>
            <tr>
                <td align="center">
                    <font size="-2">
                        <b>Example</b>
                    </font>
                </td>
                <td>
                    <font size="-2">
                        <b>Line</b>
                    </font>
                </td>
                <td>
                    <font size="-2">
                        <b>Occurences</b>
                    </font>
                </td>
                <td>
                    <font size="-2">
                        <b>Error</b>
                    </font>
                </td>
            </tr>
            <tr>
                <td>
                    <font size="-1">AFL_5279884.xml</font>
                </td>
                <td>
                    <font size="-1">
                        <a href="files/AFL_5279884.html#l4920">4920</a>
                    </font>
                </td>
                <td align="center">
                    <font size="-1">1</font>
                </td>
                <td>
                    <font size="-1">Type 'agrifgl:ENT_Comment_Category_Type' that is used in xsi:type is not derived from the type of element 'Category'</font>
                </td>
            </tr>
        </table>
    </body>
</html>
And the full XSLT is below.
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" />
    <xsl:strip-space elements="*" />

    <xsl:template match="/">
        <Errors>
            <xsl:apply-templates select="//font[descendant::text() = 'Consolidated Errors']/following-sibling::table[1]"/>
        </Errors>
    </xsl:template>

    <!-- This match fails -->
    <xsl:template match="font[descendant::text() = 'Consolidated Errors']/following-sibling::table[1]">
        <xsl:apply-templates select="tr[td[1]/font[contains(.,'xml')]]" />
    </xsl:template>

</xsl:stylesheet>
 
Old March 28th, 2011, 10:47 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

A step in an XSLT match pattern can't use following-sibling, in a match pattern that is only allowed in predicate.
As you seem to have ensured in your apply-templates that only those table elements are processed you could simply
Code:
<xsl:template match="table">...</table>
If you think you need to restrict both the select expression of your apply-templates and the match pattern then
Code:
<xsl:template match="table[preceding-sibling::font[descendant::text() = ...]]">...</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
iceandrews (March 28th, 2011)
 
Old March 28th, 2011, 10:53 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

For the short term, I did exactly what you suggested first. Since I've restricted my node set via the apply templates, I simply match on the "table" element. This work fine for now, but I will need to expand that when I have other matches on "table" nodes.

I didn't realize you couldn't do that in a match pattern. I've been doing to too long not to have come across that by now you'd think :) Appreciate the simple observation and help.

Last edited by iceandrews; March 28th, 2011 at 10:57 AM..
 
Old March 28th, 2011, 11:00 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

In the xsl:template pattern attribute you can't use axis like following-sibling - any relationships need to be strict child/parent ones.

When trying to find a template pattern to match again, it will actually be at the table element, it will then try and find a pattern that matches it by walking back up the pattern expression (so in your case from table, to following-sibling axis, then to font). Trying to move backwards up the following-sibling axis would require it to work the other way (starting at font and working down).

If you just want to have a template that matches the apply-templates above then use modes.

Code:
<xsl:template match="/">
        <Errors>
            <xsl:apply-templates select="//font[descendant::text() = 'Consolidated Errors']/following-sibling::table[1]" mode="errormode"/>
        </Errors>
    </xsl:template>

    <xsl:template match="table" mode="errormode">
        <xsl:apply-templates select="tr[td[1]/font[contains(.,'xml')]]" />
    </xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
State pattern versus Strategy Pattern disel2010 BOOK: Professional ASP.NET Design Patterns 2 March 15th, 2011 08:20 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
VB Error: Syntax Error or Access Violation codehappy VB How-To 7 October 3rd, 2007 05:41 PM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.