[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: problem with fn:contains using xsl:param

Subject: RE: problem with fn:contains using xsl:param
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 13 Dec 2009 23:06:28 -0000
RE:  problem with fn:contains using xsl:param
> I'm using Saxon-HE 9.2.0.3N to test XSLT 2.0 document I'm 
> creating. The purpose of transformation is to generate Perl 
> source code based on schema file.
> 
> I had this statement
> 
> <xsl:template match="xsd:element[contains(@type,'xsd:date') or
> contains(@type,'xsd:dateTime') or contains(@type,'xsd:bool')]">
> 
> which was working as expected and I wanted to refactor it to 
> something like this
> 
> <xsl:param name="KnownXSDTypes">xsd:date xsd:dateTime 
> xsd:bool</xsl:param>
> (...)
> <xsl:template match="xsd:element[contains($KnownXSDTypes, @type)]">
> 
> but after this change I'm getting different results. I don't 
> see how the latter code could have different meaning than the 
> former one.

Well if an element has type="xsd:boolean" then contains(@type, 'xsd:bool')
will be true, but your replacement condition will be false. 

Which illustrates why I don't think this is a good design...

(a) your code shouldn't be sensitive to the choice of prefixes used in the
source document (especially the xsd prefix, where half the community uses
"xsd" and the other half uses "xs")

(b) there are better ways of testing whether a value is one of a given list
of values:

<xsl:param name="KnownXSDTypes" as="xsd:QName*"
  select="(xsd:QName('xsd:date'), xsd:QName('xsd:dateTime'),
xsd:QName('xsd:boolean')"/>

<xsl:template match="xsd:element[QName(@type, .) = $KnownXSDTypes">

(With a schema-aware stylesheet, of course, you wouldn't have to do all the
explicit casting, this would be done automatically in the course of schema
validation).

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.