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 1st, 2007, 12:41 PM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default XPath Error

Hello,
I am getting an error when performing a transformation. Both the xml and xsl files are otherwise well-formed. Getting the following error:

Error in XPath expression, Not a node set

at the following point in xsl file

<xsl:if test="$packageCount[. > 0]">

Here is more surrounding context:

<xsl:template name="rolledUpChildren">
        <xsl:param name="childNodes"/>
        <xsl:param name="packageCount"/>
        <xsl:param name="actorCount"/>
        <xsl:param name="useCaseCount"/>
        <xsl:param name="activityCount"/>
        <xsl:if test="count($childNodes) > 0">
            <xsl:call-template name="rolledUpChildren">
                <xsl:with-param name="childNodes" select="$childNodes/ownedMember"/>
                <xsl:with-param name="packageCount" select="$packageCount + count($childNodes[@xsi:type='uml:Package'])"/>
                <xsl:with-param name="actorCount" select="$actorCount + count($childNodes[@xsi:type='uml:Actor'])"/>
                <xsl:with-param name="useCaseCount" select="$useCaseCount + count($childNodes[@xsi:type='uml:UseCase'])"/>
                <xsl:with-param name="activityCount" select="$activityCount + count($childNodes[@xsi:type='uml:Activity'])"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="count($childNodes) = 0">
            <b>
                <xsl:if test="@xsi:type='uml:Package'">
                    <xsl:if test="$packageCount[. > 0]">
                        <xsl:call-template name="indent1"/>Packages:
            <xsl:value-of select="$packageCount"/>
                    </xsl:if>
                    <xsl:if test="$actorCount[. > 0]">
                        <xsl:call-template name="indent1"/>Actors:
            <xsl:value-of select="$actorCount"/>
                    </xsl:if>
                    <xsl:if test="$useCaseCount[. > 0]">
                        <xsl:call-template name="indent1"/>UseCases:
            <xsl:value-of select="$useCaseCount"/>
                    </xsl:if>
                    <xsl:if test="$activityCount[. > 0]">
                        <xsl:call-template name="indent1"/>Activities:
            <xsl:value-of select="$activityCount"/>
                    </xsl:if>
                </xsl:if>
                <xsl:if test="@xsi:type='uml:Model'">
                    <xsl:if test="$packageCount[. > 0]">
                        <xsl:call-template name="indent1"/>Packages:
            <xsl:value-of select="$packageCount"/>
                    </xsl:if>
                    <xsl:if test="$actorCount[. > 0]">
                        <xsl:call-template name="indent1"/>Actors:
            <xsl:value-of select="$actorCount"/>
                    </xsl:if>
                    <xsl:if test="$useCaseCount[. > 0]">
                        <xsl:call-template name="indent1"/>UseCases:
            <xsl:value-of select="$useCaseCount"/>
                    </xsl:if>
                    <xsl:if test="$activityCount[. > 0]">
                        <xsl:call-template name="indent1"/>Activities:
            <xsl:value-of select="$activityCount"/>
                    </xsl:if>
                </xsl:if>
            </b>
        </xsl:if>
    </xsl:template>

Interestingly (or not..), I do not get this error when transformation is against newer version of XMLSPY (2007 sp2), but do against older (version 5 rel 2). Thanks for any help.

 
Old March 1st, 2007, 01:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's complaining that $packageCount isn't a node-set (and therefore, in XSLT 1.0, can't be filtered). So you need to look for the calling code that sets this parameter. Perhaps it doesn't set the parameter, in which case $packageCount will be a zero-length string.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 1st, 2007, 03:40 PM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Michael, oh, sort of like a null string I guess in compiled languages parlance. How do I check for zero-length or null string? Thanks so much.

 
Old March 1st, 2007, 04:41 PM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Michael, thank you for assistance. I check the length now ahead of the XPath expression.

 
Old March 1st, 2007, 07:20 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's no such thing as a null string in XPath. You can test for a zero-length string with test="$x=''". But you need to be looking at the code that calls this template to see what value it supplies for this parameter.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath Error : Expression Expected deean XML 1 June 14th, 2008 05:57 PM
xpath contains error 'has an invalid token' XMLUser XSLT 7 February 5th, 2008 02:31 AM
Xpath error in Document() bonekrusher XSLT 13 September 30th, 2006 02:39 AM
XPST0081: XPath syntax error ... with Saxon markus2000 XSLT 3 June 22nd, 2006 09:53 AM
XSLT -XPATH Error xslspy XSLT 1 October 27th, 2005 03:24 AM





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