Progress Acquires MarkLogic! Learn More
BLOG ARTICLE

Controlling Output Options

Back to blog
01.05.2012
1 minute read
Back to blog
01.05.2012
1 minute read

In the XML world, MarkLogic natively supports both XQuery and XSLT, and both languages use the same data model (XPath). In the XPath data model, XML is represented as an abstract tree of nodes. The abstract nature of the model means that certain details about XML are not included, such as a document’s encoding, its DOCTYPE declarations, whether or not you use quotes or apostrophes for your attributes, etc. But when it comes time to output the result of your program (XML, or sometimes, HTML), the resulting tree needs to be serialized. And all those gritty details about how to represent the XPath tree as a stream of bytes need to be resolved. How do you control (at least some of) these details?

In XSLT, you have some control right at the language level (assuming your processor is the one responsible for serializing the result, as MarkLogic is). You can use the <xsl:output> element to control the output. The following output declaration tells the XSLT processor to output its result in ASCII encoding, with extra indentation for better readability, using the HTML “output method” (e.g., br elements appear as <br> instead of <br/> or <br></br>):

<xsl:output encoding="us-ascii" method="html" indent="yes"/>

The XSLT 2.0 spec lists the full range of output options. But what about XQuery? As it turns out, even though they use the same data model and serialization concerns are equally well-defined for both languages, XQuery doesn’t include built-in language support for controlling these options. Fortunately, XQuery provides a generic extension mechanism for declaring processor-specific options, and even more fortunately, MarkLogic provides the exact options you need. Here’s how you’d make the same explicit determination in your XQuery code:

<xsl:output encoding="us-ascii" method="html" indent="yes"/>

Oftentimes, the default output options will serve you just fine. For example, unless you specify otherwise, XSLT will automatically use the HTML output method when the document element of the result is <html> or <HTML>.

Another way you can control the output options in MarkLogic without having to make code edits is to define the defaults at the app server level, as shown below.

System Administration: Output Options Configuration at the Appserver level

You can find this screen in the left-hand menu for your app server:

where to find App Server configuration on left side-menu of Systems Administration

Hope you enjoyed this random tip!

Share this article

Read More

Related Posts

Like what you just read, here are a few more articles for you to check out or you can visit our blog overview page to see more.

Tutorial

Poker Fun with XQuery

In this post, we dive into building a full five-card draw poker game with a configurable number of players. Written in XQuery 1.0, along with MarkLogic extensions to the language, this game provides examples of some great programming capabilities, including usage of maps, recursions, random numbers, and side effects. Hopefully, we will show those new to XQuery a look at the language that they may not get to see in other tutorials or examples.

All Blog Articles
Tutorial

Protecting passwords in ml-gradle projects

If you are getting involved in a project using ml-gradle, this tip should come in handy if you are not allowed to put passwords (especially the admin password!) in plain text. Without this restriction, you may have multiple passwords in your gradle.properties file if there are multiple MarkLogic users that you need to configure. Instead of storing these passwords in gradle.properties, you can retrieve them from a location where they’re encrypted using a Gradle credentials plugin.

All Blog Articles
Tutorial

Getting Started with Apache Nifi: Migrating from Relational to MarkLogic

Apache NiFi introduces a code-free approach of migrating content directly from a relational database system into MarkLogic. Here we walk you through getting started with migrating data from a relational database into MarkLogic

All Blog Articles

Sign up for a Demo

Don’t waste time stitching together components. MarkLogic combines the power of a multi-model database, search, and semantic AI technology in a single platform with mastering, metadata management, government-grade security and more.

Request a Demo