TECHS5: Lecture 4

During this lecture, we’ll get acquainted with the while loop and look into ways we can harness its amazing powers to repeat stuff lots and lots of times. Next, we’ll move on to for loops and supercharge our iterable-handling powers.

Lecture View Gist

TECHS5: Lecture 3

The third lecture starts with a quick recap of what we learned last week. Then, we will take a look at the different data structures – lists, tuples and dictionaries – we have at our disposal, and start figuring out how and why we should use them. Once we’ve mastered them all, we’ll move on to loops, starting with the while loop.

If time permits, which it probably won’t, we’ll also have a look at for loops.

Lecture

TECHS5: Lecture 2

The second lecture starts with a quick recap of what we learned last week. After that, we’ll look into different functions that we can use to work with strings and other sequences. Then, we’ll learn about Boolean data types and conditional statements and see how they can be used to control the flow of our programs. We’ll also have a look at the various logical operators we can use in conditional statements. Finally, if time permits, we’ll look at the different data structures – lists, tuples and dictionaries – we have at our disposal.

Lecture

Highlighting stuff in Google Forms

Google Forms is a simple, handy tool for creating quizzes and questionnaires. One thing that slightly bugs me with Google Forms, though, is that there are currently no tools available for formatting the text in the quizzes. This makes it a bit difficult to add, fox example, bits of code in the quiz questions and highlight them properly.

However, as this article at GAFE points out, you can use a handy Unicode text converter to convert strings of ASCII text to various styles created with Unicode characters. For bits of code, the converter produces a nice monospaced variant that you can simply copy-paste to Google Forms.

TECHS5: Lecture 1

Lecture one starts from the very basics. First, we’ll take a look at why this course is on the curriculum (there’s a solid reason!) and have a brief look at all the fun things you’ll learn about during the course:

  • Variables
  • Playing with numbers
  • Working with text
  • Conditional statements
  • Data structures
  • Loops
  • Functions
  • File handling

After the introduction, we’ll jump straight into Python and get to know both the Python Shell and IDLE. We’ll then get acquainted with variables and start using them with numbers and do a (tiny) bit of math. Next, we’ll move onto text, or strings, and figure out how to print stuff, manipulate text and ask for user input in Python.

Download files:

Lecture Sidetrack Slides Sidetrack Exercises

Note to self: Customizing the way XMetaL behaves

I usually work on DITA modules with Oxygen XML Editor, but some of my colleagues prefer to use XMetaL for their editing needs. They are mostly happy with the tool, but found some of the out-of-the-box features a bit annoying.

Updating the topic type templates

Whenever you create a new topic with XMetaL, the editor adds the following comment on each new topic:

xmetal-comment

This is not a big deal and it doesn’t really affect the published content, but having to look at the comment might bug some authors. So, let’s make it go away.
(more…)

Note to self: Passing parameter values to XSLT stylesheets with Saxon and .Net

I recently worked on a little .Net project that involved running some XSLT transformations with the help of Saxon API for .Net. At one point, I needed to pass a parameter value – a target path – from C# onto an XSLT stylesheet.

After a bit of digging, I found out that you can use the XdmAtomicValue class to pass a value to a stylesheet.

First, pick up Saxon-HE through NuGet, and add a reference to it:

using Saxon.Api;

Next, setup the files you want to use:

var stylesheet = new FileInfo(@"C:\your\file\stylesheet.xsl");
var inputFile = new FileInfo(@"C:\your\file\input.xml");
var outputFile = new FileInfo(@"C:\your\file\output.xml");

Then, compile your stylesheet:

var processor = new Processor();
var compiler = processor.NewXsltCompiler();
var executable = compiler.Compile(new Uri(stylesheet.FullName));

After that, setup the transformer and transform the input document to a set destination:

var destination = new DomDestination();
using (var inputStream = inputFile.OpenRead())
{
    var transformer = executable.Load();
    transformer.SetInputStream(inputStream, new Uri(inputFile.DirectoryName));

    // Create and set the parameter
    XdmAtomicValue parameter = new XdmAtomicValue("Parameter String");
    transformer.SetParameter(new QName("parameterNameInXSLT"), parameter);
    transformer.Run(destination);
}

Finally, save the resulting to your destination of choice:

destination.XmlDocument.Save(outputFile.FullName);

Note that the parameter name you use in transformer.SetParameter() must match the parameter name in your XSTL stylesheet. In this case, you should have the following line in your XSLT stylesheet:

<xsl:param name="parameterNameInXSLT"/>

Dealing with HTML tags and inline items in Passolo

I’ve been using Passolo to deal with UI strings for nearly four years now. Our relationship hasn’t always been the happiest one, but so far, Passolo has been a good enough tool to deal with the .properties style UI strings that I work with:

service.common.username=Username
service.common.phone=Phone number

All it takes to get underway in Passolo is a simple parser that recognizes the part before the = sign as the ID and the part after it as the string. Easy peasy.

Dealing with parameters

Sometimes, we need to present dynamic content like dates, usernames and document IDs on our UI. In these cases, our developers drop in the necessary values as parameters using curly brackets:

service.common.loggedInAs=You're logged in as {0}
service.common.viewingDocument=Viewing document {0} from {1}

Each parameter takes up just three characters, so you’d think there’s no need to have any special treatment for these, right? I have noticed that sometimes – not very often, though – some of our translators have accidentally deleted either the opening or the closing bracket. When we bake strings like those into the software, stuff tends to break and cause me grey hair. And that’s not nice.

The Inline Patterns tool

To combat broken parameters and grey hair, SDL has added a tool to Passolo that lets you define inline patterns that may appear in your UI strings. You can find it under the Project tab:

passolo-inline-patterns-menuitem

When you click Inline Patterns, Passolo pops up the Inline Patterns window. This is where all the magic happens.

passolo-inline-patterns-window

(more…)

Lecture 7: Working with functions and watching out for errors

During the final lecture, we’ll continue looking at functions. We’ll find out how we can return values from our own functions and look at cases where return values come in handy. If time permits, we’ll have a quick look at how Python lets us anticipate errors and deal with them in ways that won’t break our programs.