XSL: pattern is empty

Discussion in 'XML' started by Tjerk Wolterink, Nov 17, 2004.

  1. I have an xsl file wich xsl:includes this file:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
    xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent">

    <xsl:eek:utput method="xml" indent="yes"/>

    <xsl:param name="absolute_url"/>
    <xsl:param name="upload_url"/>

    <!--
    ! Default template for an image
    !
    !-->
    <xsl:template name="image">
    <xsl:param name="max_width" select="200"/>
    <xsl:param name="img"/>
    <xsl:if test="$img[xc:width]">
    <xsl:choose>
    <xsl:when test="$img[xc:error]/">
    <b><xsl:value-of select="$img/xc:error"/></b>
    </xsl:when>
    <xsl:eek:therwise>
    <img>
    <xsl:attribute name="src">
    <xsl:value-of select="$upload_url"/>/<xsl:value-of select="current()"/>
    </xsl:attribute>
    <xsl:if test="$img/@width>$max_width">
    <xsl:attribute name="width"><xsl:value-of select="$max_width"/></xsl:attribute>
    </xsl:if>
    </img>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:if>
    </xsl:template>

    <!--
    ! All html should remain html
    !-->
    <xsl:template match="*[namespace-uri(.) != namespace::xc]">
    <xsl:copy>
    <xsl:for-each select="@*">
    <xsl:copy/>
    </xsl:for-each>
    <xsl:apply-templates select="./node()"/>
    </xsl:copy>
    </xsl:template>

    </xsl:stylesheet>




    But now i get teh folowing error:

    array(7) {
    ["msgtype"]=>
    string(5) "error"
    ["code"]=>
    string(2) "19"
    ["module"]=>
    string(9) "Sablotron"
    ["URI"]=>
    string(36) "file://C:/webserver/xsl/standard.xsl"
    ["line"]=>
    string(2) "22"
    ["node"]=>
    string(20) "element ''"
    ["msg"]=>
    string(16) "pattern is empty"
    }

    So on line 22:
    line 22: <xsl:when test="$img[xc:error]/">
    the patternt is empty.

    But $img should be a variable to a node, i tried <xsl:when test="current()[xc:error]/">
    But that does not work.

    What i want to do is call the template with name "image" whenever some element is found,
    i give that element as an param $img with the template named "image".

    But my xsl file that the above xsl includes do not ever call the template named "image".
    So why is there an error??!?!?!

    What does "pattern is empty" realy mean?
    Tjerk Wolterink, Nov 17, 2004
    #1
    1. Advertising

  2. Tjerk Wolterink

    Joris Gillis Guest

    Joris Gillis, Nov 17, 2004
    #2
    1. Advertising


  3. > But $img should be a variable to a node, i tried <xsl:when
    > test="current()[xc:error]/"> But that does not work.


    if $img is your current node, then you can just say
    test="xc:error"
    which is simpler.

    > What does "pattern is empty" realy mean?


    It is most odd that you get an error like that from that line (are your
    sure your processor isn't confused about the line number) a pattern is a
    specific XSLT construct that appears in match attributes and certain
    attributes of xsl:number, but never appears in a select or test
    attributes which always take an arbitrary XPath expression not a pattern.

    > <!--
    > ! All html should remain html
    > !-->
    > <xsl:template match="*[namespace-uri(.) != namespace::xc]">
    > <xsl:copy>
    > <xsl:for-each select="@*">
    > <xsl:copy/>
    > </xsl:for-each>
    > <xsl:apply-templates select="./node()"/>
    > </xsl:copy>
    > </xsl:template>



    You can write the body of that more simply (and equivalently) as


    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
    </xsl:copy>

    rather than test against the namespace axis it's probably simpler just
    to have
    <xsl:template match="*">

    so that it matches everything. For the xc elements you can then have

    <xsl:template match="xc:*">
    which does whatever you want to do for those. This will have a higher
    default priority so your default copy template will not apply to xc
    elements.

    David
    David Carlisle, Nov 17, 2004
    #3

  4. >> <xsl:if test="$img[xc:width]">

    > Shouldn't that be <xsl:if test="$img/xc:width"/> ?


    the two constructs are equivalent.

    David
    David Carlisle, Nov 17, 2004
    #4
  5. Tjerk Wolterink

    Joris Gillis Guest

    >>> <xsl:if test="$img[xc:width]">
    >> Shouldn't that be <xsl:if test="$img/xc:width"/> ?

    >
    > the two constructs are equivalent.


    Do you mean that the Xpath expressions return exactly same?
    I would find that most unlikely.
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Nov 17, 2004
    #5
  6. "Joris Gillis" <> writes:

    > >>> <xsl:if test="$img[xc:width]">
    > >> Shouldn't that be <xsl:if test="$img/xc:width"/> ?

    > >
    > > the two constructs are equivalent.

    >
    > Do you mean that the Xpath expressions return exactly same?
    > I would find that most unlikely.


    unlikely or not, it's true:)

    $img[xc:width] and $img/xc:width of course would select different
    things, but when used as a test expression there is an implied boolean()
    around them and
    boolean($img[xc:width]) and boolean($img/xc:width)
    are equivalent Xpath expressions.

    they are true just in case the node sets supplied to boolean() are
    non-empty, and in either case, that is true only if there is an element
    in $img that has a child with name xc:width.

    David
    David Carlisle, Nov 17, 2004
    #6
  7. Tjerk Wolterink

    Joris Gillis Guest

    > unlikely or not, it's true:)
    >
    > $img[xc:width] and $img/xc:width of course would select different
    > things, but when used as a test expression there is an implied boolean()
    > around them and
    > boolean($img[xc:width]) and boolean($img/xc:width)
    > are equivalent Xpath expressions.
    >
    > they are true just in case the node sets supplied to boolean() are
    > non-empty, and in either case, that is true only if there is an element
    > in $img that has a child with name xc:width.


    Oh, that way. I understand:)
    The implied boolean operator slipped my mind somehow...

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Nov 17, 2004
    #7
  8. David Carlisle wrote:

    >> But $img should be a variable to a node, i tried <xsl:when
    >> test="current()[xc:error]/"> But that does not work.

    >
    >
    > if $img is your current node, then you can just say
    > test="xc:error"
    > which is simpler.
    >


    Well, then here my question.
    If i am in a xsl:template and there i call another template using xsl:call-template
    Then does there exists a current() or . node in the call-template?

    If-yes then the problem is somewhere else.

    >
    >>What does "pattern is empty" realy mean?

    >
    >
    > It is most odd that you get an error like that from that line (are your
    > sure your processor isn't confused about the line number) a pattern is a
    > specific XSLT construct that appears in match attributes and certain
    > attributes of xsl:number, but never appears in a select or test
    > attributes which always take an arbitrary XPath expression not a pattern.
    >
    >
    >><!--
    >> ! All html should remain html
    >> !-->
    >><xsl:template match="*[namespace-uri(.) != namespace::xc]">
    >> <xsl:copy>
    >> <xsl:for-each select="@*">
    >> <xsl:copy/>
    >> </xsl:for-each>
    >> <xsl:apply-templates select="./node()"/>
    >> </xsl:copy>
    >></xsl:template>

    >
    >


    Ok but then, the <xs:template name="image"> element does not have an match attribute
    how can the error be there?

    >
    > You can write the body of that more simply (and equivalently) as
    >
    >
    > <xsl:copy>
    > <xsl:copy-of select="@*"/>
    > <xsl:apply-templates/>
    > </xsl:copy>


    ok that's nice

    >
    > rather than test against the namespace axis it's probably simpler just
    > to have
    > <xsl:template match="*">
    >
    > so that it matches everything. For the xc elements you can then have
    >
    > <xsl:template match="xc:*">
    > which does whatever you want to do for those. This will have a higher
    > default priority so your default copy template will not apply to xc
    > elements.
    >


    hmm, that was not my question, but the stylesheet is more complex that i have shown here,
    and there are 5 different namespaces, so the way i do it is better for the job.

    > David
    >
    Tjerk Wolterink, Nov 17, 2004
    #8
  9. In article <cnfrt8$3t2$>,
    Tjerk Wolterink <> wrote:

    >If i am in a xsl:template and there i call another template using
    >xsl:call-template
    >Then does there exists a current() or . node in the call-template?


    call-template does not change the current node.

    -- Richard
    Richard Tobin, Nov 17, 2004
    #9
  10. haha i found what i did wrong:

    >line 22: <xsl:when test="$img[xc:error]/">
    >the patternt is empty.


    I forgot ti remove the / char at the end in the xpath expression: $img[xc:error]/
    should be: $img[xc:error]
    Tjerk Wolterink, Nov 17, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,014
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Replies:
    1
    Views:
    3,590
    A. Bolmarcich
    May 27, 2005
  3. Lukas
    Replies:
    3
    Views:
    789
    spiff
    Nov 10, 2005
  4. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    566
    Dave Thompson
    Feb 14, 2004
  5. Brian Roberts

    empty lists vs empty generators

    Brian Roberts, May 3, 2005, in forum: Python
    Replies:
    12
    Views:
    648
    Jeremy Bowers
    May 4, 2005
Loading...

Share This Page