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 September 17th, 2014, 05:53 AM
Authorized User
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default Pattern matching throwing an Exception

I've the below 2 XML Files.

Title.XML

<?xml version="1.0" encoding="UTF-8"?>
<entry>
<file name="LCCPMY_CH_01.xml"></file>
</entry>
Contents.xml

Code:
<toc-pg>1</toc-pg>
and the content of LCCPMY_CH_01.xml is as below.

Code:
<chapter num="A">
    <section level="sect1">
    <page num="1"/>
        <title>
            <content-style font-style="bold">Chapter 1: This is Chapter</content-style>
        </title>
        </section>
</chapter>
here what i'm trying to do is from Content.xml file, by using the help of Title.xml file, i'm trying to match the number(page num of LCCPMY_CH_01.xml is equal to Contents.xml toc-pg value). I'm using the below XSLT to do it.

Code:
<xsl:template match="toc-pg" mode="x">
<xsl:variable name="dot" select="."/>
    <xsl:analyze-string select="." regex="([0-9]+)">
        <xsl:matching-substring>
            <xsl:variable name="prent">
                <xsl:for-each select="document('C:\Users\u0138039\Desktop\Proview\MY\2014\The Law of Costs in Civil Proceedings\title.xml')/entry/file">
                    <xsl:value-of select="normalize-space(document(concat('C:\Users\u0138039\Desktop\Proview\MY\2014\The Law of Costs in Civil Proceedings\',./@name))/chapter/section[@level='sect1']/substring-after(fn:substring-before(.,':'),' ')[//page/@num=$dot]|a[//page/@num=$dot])"/>
                </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="cha">
                <xsl:value-of select="$prent"/>
            </xsl:variable>
            <xsl:variable name="size">
                <xsl:value-of select="string-length($cha)"/>
            </xsl:variable>
            <xsl:variable name="conct">
                <xsl:choose>
                    <xsl:when test="$size>'1'">
                        <xsl:value-of select="concat('er:#LCCPMY_CH_',$cha,'/pg_',.)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="concat('er:#LCCPMY_CH_0',$cha,'/pg_',.)"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <a href="{$conct}">
                <xsl:value-of select="regex-group(1)"/>
            </a>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:value-of select="."/>
        </xsl:non-matching-substring>
    </xsl:analyze-string>
</xsl:template>
but when i'm running this I'm getting the below Exception.

Code:
XSLT 2.0 Debugging Error: Error: file:///C:/Users/u0138039/Desktop/Proview/MY/2014/The%20Law%20of%20Costs%20in%20Civil%20Proceedings/09172014/XSLT/MCCL_TOC_01.xsl:235: Not a node item - item has type xs:string with value '1' -   Details: -     XPTY0020: The context item in an axis step must be a node
please let me know where am i going wrong and how can i fix this. I use XSLT 2.0.
The error is thrown here
Code:
<xsl:value-of select="normalize-space(document(concat('C:\Users\u0138039\Desktop\Proview\MY\20‌​14\The Law of Costs in Civil Proceedings\',./@name))/chapter/section[@level='sect1']/substring-after(fn:subst‌​ring-before(.,':'),' ')[//page/@num=.]|a[//page/@num=.])"/>
Thanks
 
Old September 17th, 2014, 06:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

where you do this:

Code:
substring-after(substring-before(.,':'),' ')[//page/@num=$dot]
the //page is being selected with the result of substring-after() as the context item; you can't select a node starting at a string. I think you are missing some parentheses somewhere.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old September 17th, 2014, 07:42 AM
Authorized User
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi mhkay,

Here i want to retrieve `1` from

Code:
 <content-style font-style="bold">Chapter 1: This is Chapter</content-style>
can you please assist me edit my code.

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Throwing an exception from a SqlDataSource member4953 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 29th, 2009 03:25 PM
RangeValidaor throwing exception anup_daware .NET Framework 1.x 0 March 16th, 2006 07:54 AM
javascript pattern matching... rbd Javascript 1 October 7th, 2004 12:20 PM
PHP Pattern Matching joanncae BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 May 17th, 2004 04:52 PM
Pattern Matching using PHP spraveens PHP Databases 2 March 23rd, 2004 10:03 PM





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