Home > SOA Tips > XML Developer > XSLT expression variables and data types
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

XML DEVELOPER

XSLT expression variables and data types


Ed Tittel
08.24.2005
Rating: -3.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


booleanLogical variables may take values of either true or false, and those values result from invoking the functions true() and false(), respectively. Logical comparison operators «=» (equals) and «!=» (not equals) may be combined with logical operators «and» and «or» as well as the logical function not(). Boolean variables must always be either true or false; no null or undefined values are allowed.
numberA number is a double-precision 64-bit floating point number, defined in accordance with the IEEE 754 standard for floating point arithmetic. It's the same scheme used in Java. Valid operators include numerical comparison («<», «<=», «>», «>=»), numerical equality («=»,«!=»), unary minus («-»), multiplicative («*»,«div»,«mod»), additive («+»,«-»), numeric selection functions round(), ceil() and floor() to convert numbers to integers, and the function sum(), which totals numeric values of a set of nodes. The number() function converts any value to a number, string() and format-number() functions convert strings to numbers, and the boolean() function converts a number to a boolean value.
stringAny sequence of zero or more character values, where the possible alphabet maps to Unicode. String values are written as literals, enclosed either in single or double quotes, as in 'Bob' or "Alice" (this mechanism was designed to permit one type of quote to be treated as a literal, but because XPath expressions normally appear inside XML attributes, this doesn't work as intended; the other quote marks are already "taken"). Use character entities to reproduce necessary diacritical and syntax-sensitive characters in literals for best results. Compare strings using the «=», «!=» operators. A translate() function is available to convert between upper and lowercase alphabetical characters. The string-length function() returns the numeric length of XML characters included (not the total count of all 16-bit Unicode character codes).
node-setA set of nodes in a source document tree, when multiple source document trees are in use, a node-set may combine nodes from more than one tree. Any node in a node-set may be any type of node, and different types can occur within the same node set. A node can appear only once in a set, but order of appearance is not significant (though nodes tend to be processed in "document order" reflecting their position in the source document tree). A single node takes the form of a node set with a single member.
treeA value of type tree (formally called a result tree fragment) contains a root node, where the root may have zero or more children. As a fragment, a tree value does not necessarily correspond to a well-formed XML document and may thus violate well-formedness constraints in various ways (the root node may own text nodes directly; multiple element nodes may occur among its children). A tree value must still adhere to the rules that apply to an external parsed XML entity, meaning that all attributes must have unique names and all attribute values be properly represented, and so forth. XSLT supports only two operations on trees once they're constructed: They can be copied to the current destination tree (the result tree of some other tree variable using <xsl:copy-of> or the tree value may be converted to a string, resulting in concatenation of all text nodes in that tree. Trees are constructed by processing an <xsl:variable> declaration. The XSLT fragment shown in Listing 1 produces a specific tree instance, depicted in Listing 2.

Listing 1: Defining a tree variable's value using <xsl:variable>

Listing 2: Tree graph for <xsl:variable> declaration (note: each node consists of three lines - the first identifies the node type, the second its name (a blank means no names is associated to the node) and the third its string value; an asterisk indicates the value is the concatenation of the string value of its children)

For the incurably curious, the string value that the <xsl:variable> declaration in Listing 1 produces is "TheRainInSpain." Notice also how nodes with no string values produce no output and how concatenation from children through parents permits the string to read from left to right, as graphed in Listing 2.

booleannumberstringnode-settree
booleanN/Afalse 0
true 1false 'false'
true 'true'N/AN/A
number0 false
other trueN/Aconvert to
decimal formN/AN/A
stringnull false
other trueparse as
decimal numberN/AN/AN/A
node-setempty false
other trueconvert via
stringstring-value of
1st node in
document orderN/AN/A
treeconvert via
stringconvert via
stringconcatenate all
text nodes in
fragmentN/AN/A

This information sets the stage for our next tip, in which we'll dig into some details related to XSLT expressions and how they may be used. Please note that the information in Table 2 is reproduced directly from information on pages 80 and 81 of Michael Kay's outstanding book XSLT Programmer's Reference (Wrox, 2000, ISBN: 1861003129), still one of my very favorite resources on this subject.

About the author
Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. E-mail Ed with comments, questions, or suggested topics or tools for review.

This is the fourth segment of what was planned as an eight-part series on XML eXtensible Stylesheets Language Transformations, aka XSLT. The subject of this brief tutorial was supposed to be XSLT expressions, which employ variables and data types to seek out specific XSLT document elements and patterns to drive parsing of XML documents, and transform them into XML and other output formats. To some extent, this makes XSLT expressions the "transformation engine" inside XSLT, at least when input must be parsed, interpreted, reacted to, or manipulated in some form or fashion.

That said, complete coverage of XSLT expressions proves to be too big a subject to cover in a single tutorial tip. Thus, in this fourth of what now looks to nine total parts, we cover XSLT variables and data types used in expressions, and will dig into XSLT expressions themselves more deeply in our next tip. In the meantime, this tip digs you into XPath, which provides the foundation for XSLT expressions, and related variables and data types. Please read on and all this gibberish should start making some sense.

XSLT expressions are really XPath expressions (they're identical in syntax, structure and use). It's impossible to understand XSLT/Xpath expressions without also understanding XSLT/XPath variables and data types, so we take a tour through these topics here. Please consult any references in the XSLT tutorial series kick-off tip for additional information, discussion and examples on these topics as needed:

  • Variables:As in many programming languages, XSLT scopes variables globally (spans an entire XSLT document and processing context) or locally (spans a single template body). If a variable declaration (which usually takes a form like <xsl:variable name="count" select="10"/>) occurs at the top level in an XSLT document (making it a child of xsl:stylesheet or other valid document elements) it's global; if a variable declaration occurs within a template body (making it a child of some xsl:template element) it's local.
  • Data Types: XSLT is a dynamically typed language, meaning that data types are associated with values rather than variables, in much the same way as in JavaScript or VBScript. XSLT follows XPath in its naming and behavior, and recognizes five distinct data types where conversion between types occurs automatically as the processing context demands. Explicit conversion functions named string(), number() and boolean() may be used to force conversion. Table 1 describes data types individually; Table 2 describes all valid conversions between pairs of types (N/A indicates that a conversion is not allowed or doesn't apply, as when converting a type to itself).

Table 1: ...

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
XML Developer
Use the soapUI software tool to tame WSDL
WSDL 2.0, new messaging for Web services
Using RELAX NG For data integration
Efficient XML Interchange tackles data verbosity
XML to DDL imports, synchronizes database schemata
The basics of MathML 3.0
Migrating to XSLT 2.0
What's up with XML 2.0?
Say hello to XPath 2.0
Podcasting software covers many bases

XML and XML schema
What's the future of XML?
SOA pattern of the week (#7): policy centralization
Try XML-based Extensible Business Reporting Language (XBRL) for accounting reports
What's new at the W3C
Ganymede: Modeling tools target SOA, UML
Data services mashups emerge for SOA
Making sense of data services mashups
XML turns 10
SOA helps save 100-year-old business
Oracle maps heterogeneous data services strategy for SOA

XML security
Verizon uses BPEL app to cut down on code, check for fraud, and go green
Layer 7 adds SPARC
Oracle maps heterogeneous data services strategy for SOA
Partnership aims at governance for SOA and Web 2.0
SOA, Web services create software security challenges
Efficient XML Interchange tackles data verbosity
XML to DDL imports, synchronizes database schemata
The case against WS-Security
Layer 7 offers SOA 'virtual soft-appliance'
XQuery 1.0: A long time coming, now what?

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
class diagram  (SearchSOA.com)
Fast Infoset (FI)  (SearchSOA.com)
GeoRSS  (SearchSOA.com)
Keyhole Markup Language  (SearchSOA.com)
RELAX NG  (SearchSOA.com)
state diagram  (SearchSOA.com)
Universal Business Language  (SearchSOA.com)
Vector Markup Language  (SearchSOA.com)
XML infoset  (SearchSOA.com)
XML pipeline  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


XSLT Data Types

Table 2: XSLT Data Type Conversions

Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts