CDATA Sections Jeni Tennison >I have this Javascript in my xsl : > ><script language="JavaScript"> ><![CDATA[function image(){ > window.open(' NOT YET DEFINED '); >} >]]> ></script> > >I would like to know how to make the method "WINDOW.OPEN" work with a >variable that would get the information which is stored in the IMAGE >element of my xml, so putting the image in the opening window. I will have >340 different xml pages, one for each expression of the encyclopedia. From what I gather, you are generating this script element as part of the output HTML from a stylesheet. I'm sure you're aware of this, so I guess that the problem you're having is inserting this into the javascript. then it would be within a CDATA section, and would thus not be interpreted as XSLT (or XML for that matter). Within the XSLT stylesheet, the CDATA section is purely a utility to stop you from having to escape all the '<' etc. that you would have to otherwise. as there are no peculiar characters to be escaped within it. <!
Ruby/XML, XSLT and XPath Tutorial What is XML ? The Extensible Markup Language (XML) is a markup language much like HTML or SGML. This is recommended by the World Wide Web Consortium and available as an open standard. XML is a portable, open source language that allows programmers to develop applications that can be read by other applications, regardless of operating system and/or developmental language. XML is extremely useful for keeping track of small to medium amounts of data without requiring a SQL-based backbone. XML Parser Architectures and APIs: There are two different flavors available for XML parsers: SAX-like (Stream interfaces) : Here you register callbacks for events of interest and then let the parser proceed through the document. SAX obviously can't process information as fast as DOM can when working with large files. SAX is read-only, while DOM allows changes to the XML file. Parsing and Creating XML using Ruby: The most common way to manipulate XML is with the REXML library by Sean Russell. DOM-like Parsing:
LexEv XMLReader - Convert lexical events such as entity references and cdata sections into markup Options You can control the following features of LexEv: enable/disable the marking up of entity references enable/disable the marking up of character references enable/disable the marking up of CDATA sections set the default namespace for the CDATA section markup enable/disable the reporting of the DOCTYPE enable/disable the marking up of comments You can set these through the API (if you are including LexEv in an application), or from the command line using the following system properties: com.andrewjwelch.lexev.inline-entities com.andrewjwelch.lexev.character-references com.andrewjwelch.lexev.cdata com.andrewjwelch.doctype.cdataNamespace com.andrewjwelch.lexev.doctype com.andrewjwelch.lexev.comments For example to set a system property from the command line you use: -Dcom.andrewjwelch.lexev.comments=false All of these are enable by default.
Nicholas' Adventures: Nokogiri - Cut With Precision Many times we as developers have to deal with complex data, be it an ActiveResource result set or a HTML/XML document. Trying to parse data out of these using for each and nesting loops within loops can be cumbersome. A more elegant solution is to use nokogiri and xpath. Nokogiri is a type of Japanese saw, it also is a gem in Ruby that you can use to easily deal with XML or HTML documents. $ sudo gem install nokogiri Now consider the following XML document: foods.xml Before we can work with our data we need to read XML into Nokogiri. > require 'rubygems' > require 'nokogiri' > doc = Nokogiri::XML.parse(File.read('foods.xml')) => #<Nokogiri::XML::Document:0x3f930c9db884 ... What we are returned is a Nokogiri document which is a collection of Nokogiri elements and text objects. So for example if we wanted to know all the names of the food items in our document we simply say: > doc.xpath("//name").collect(&:text) => ["carrot", "tomato", "corn", "grapes", "orange", "pear", "apple"] Learn More
XSL Identity Transforms On this site, XSL means XSLT. Don’t be alarmed. Many developers have a hard time getting started with XSL. One difficulty lies in the fact that XSL favors a recursive processing style. XML is an increasingly fundamental part of the technology landscape. Pull vs. In the simplest XSL transforms, a single template like the one below pulls content from an XML document into the transform output: 1 |<NameTag xmlns:xsl=" | xsl:version="1.0 ">3 | My name is: 4 | <b><xsl:value-of select="/Customer/Name" /></b>5 |</NameTag> Any literal content items within the template, like the “My name is:” text on line three and the <b> tags on line four, are simply copied to the output. 1 |<NameTag>2 | My name is: 3 | <b>Sam Page</b>4 |</NameTag> A pull approach is very straightforward, but when pull-style templates get large, they are a mess to maintain. The following style sheet demonstrates a push approach: Processing begins with the Customer template. 1 |<? Variations 1 |<?
Nokogiri From a String We’ve tried to make this easy on you. Really! We’re here to make your life easier. The variables html_doc and xml_doc are Nokogiri documents, which have all kinds of interesting properties and methods that you can read about here. We’ll cover the interesting bits in other chapters. From a File Note that you don’t need to read the file into a string variable. Clever Nokogiri! From the Internets I understand that there may be some HTML documents available on the World Wide Web. Parse Options Nokogiri offers quite a few options that affect how a document is parsed. NOBLANKS - Remove blank nodesNOENT - Substitute entitiesNOERROR - Suppress error reportsSTRICT - Strict parsing; raise an error when parsing malformed documentsNONET - Prevent any network connections during parsing. Here’s how they are used: Or Encoding Strings are always stored as UTF-8 internally. Some documents declare one particular encoding, but use a different one. Remember that data is just a stream of bytes.
Top Ten Java and XSLT Tips My new book, Java and XSLT, examines techniques for using XSLT with Java (of course!). This article highlights ten tips that I feel are important, although limiting the list to ten items only scratches the surface of what is possible. Most of these tips focus on the combination of Java and XSLT, rather than on specific XSLT (Extensible Stylesheet Transformations) techniques. For more detailed information, there are pointers to other valuable resources at the end of this article. The basics of XSL transformations are pretty simple: one or more XSLT stylesheets contain instructions that define how to transform XML data into some other format. XSLT processors do the actual transformations; Sun Microsystems' Java API for XML Processing (JAXP) provides a standard Java interface to various processors. You can click here to download a small ZIP file containing this example, along with an XSLT stylesheet and XML data file. Cache whenever possible. Use <xsl:import> for i18n. Figure 3.
Getting Started with Nokogiri and XML in Ruby | 58bits Here's a short post on getting started with Nokogiri - a Ruby gem that wraps libxml. I'm writing this because well, the docs at Nokogiri kind of suck. I wanted to read a simple XML document. My XPath fu was a little rusty, although all I wanted to do was read some attributes from a root element, some element values off of the root, and then a short collection of items (very similar to an Atom document). My main bone of contention with the Nokogiri docs was their use of the @doc.xpath("//character") search operator at the very beginning of their parsing tutorial. How about we start from the beginning: Here is a sample XML document. <Collection version="2.0" id="74j5hc4je3b9"><Name>A Funfair in Bangkok</Name><PermaLink>Funfair in Bangkok</PermaLink><PermaLinkIsName>True</PermaLinkIsName><Description>A small funfair near On Nut in Bangkok. From our IRB prompt - the first thing we'll do is require nokogiri. >> require 'nokogiri' => true Now let's load our XML document. or >> f.close