473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XSL: pattern is empty

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:output 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:otherwise>
<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:otherwise>
</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?
Jul 20 '05 #1
9 2213
> <xsl:if test="$img[xc:width]">
Shouldn't that be <xsl:if test="$img/xc:width"/> ?
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
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

Jul 20 '05 #3
<xsl:if test="$img[xc:width]">

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


the two constructs are equivalent.

David
Jul 20 '05 #4
>>> <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-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #5
"Joris Gillis" <ro**@pandora.be> 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
Jul 20 '05 #6
> 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-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #7
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

Jul 20 '05 #8
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]
Jul 20 '05 #9
In article <cn**********@netlx020.civ.utwente.nl>,
Tjerk Wolterink <tj***@wolterinkwebdesign.com> 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
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nagi Peters | last post by:
Hello I try to tranform a XML Document in php/Sablotron with the following XSL Stylesheet. I tried to write "@id='1'" with the variable chapter_id. So it works: <xsl:variable...
2
by: David Nedrow | last post by:
OK, I have a problem which I'm guessing is simply my inability to figure out a select pattern in XSL. I have an XML file similar to the following: <?xml version="1.0"?> <?xml-stylesheet...
1
by: anonymous | last post by:
Given a sample like the one below, how can I count the number of elements <quick> with the value 'yes'. When processing the //quick nodes I can easily find out if they are 'empty' but I need to...
6
by: Matt | last post by:
How can XSL detect empty elements, for example, <author></author> or <author/> ?? The XML structure can be <book> <author></author> <title></title> </book> The XSL has the following
5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
3
by: Andy Fish | last post by:
Hi, I'm trying to use <xsl:number> to generate a sequence number of all nodes that match a particular pattern, e.g: <xsl:template match="foo"> <xsl:copy> <xsl:attribute name="id"><xsl:number...
5
by: KJ | last post by:
I would like to know if there is a tool for download or purchase that will generate a skeleton xslt document, inserting all the xsl:template's matching each element specified in any given xsd. ...
6
by: sheinaz | last post by:
Hi I am tryign to use this to print my table in landscape by default. i am new at the xsl and need some assistance. when i try to use the following i get the error: Cannot view XML input using...
1
Dormilich
by: Dormilich | last post by:
Hi, I'm running into a problem with the <xsl:processing-instruction> element (Sablotron). purpose: I generate a xhtml fragment from a xml file via xslt. This is printed (echo) to the output...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.