Serna XML Editor is Now Open Source

Good news - the free software community has a new contender for editing XML documents:

Serna Free - Open Source XML Editor

I haven't tried it yet, but the screenshots look nice. Thankfully the code is really free - no major hurdles to access the raw source. I went ahead and mirrored it at Docunext Mirrors, just in case:

Serna-free source code at Docunext Mirrors

Circular Processing with XSL

The idea is to feed the output of a stylesheet back into itself, but how can the process be managed, not infinite?

Andrew Welch suggests:

You can do all the transformations in your pipeline in one stylesheet by performing transformations within variables, with each variable operating on the previous one.

So, as top-level variables you could have:

<xsl:variable name="firstVar-rtf">
<xsl:apply-templates/>
</xsl:variable>
<xsl:variable name="firstVar" select="exsl:node-set($firstVar-rtf)"/>


<xsl:variable name="secondVar-rtf">
<xsl:for-each select="$firstVar">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="secondVar" select="exsl:nodet-set($secondVar-rtf)"/>


Here $firstVar operates on the source xml, and $secondVar works on the 'result' of the apply-templates in $firstVar.

The final link in the chain is of course:

<xsl:template match="/">
<xsl:for-each select="$lastVar">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>


All you need to do is separate out your problem into logical steps and perform each one in a varaible.

I do this a lot when xslt 1.0 struggles to do a task in one go, such as finding the average of two percentages written as 45% and 55%.

The first variable would translate() the '%' away, the second variable would find the average.

Dimitre notes:

This will select just the root node (/) of the temporary tree contained in $firstVar

Must be:

<xsl:for-each select="$firstVar/node()">
> <xsl:apply-templates/>
> </xsl:for-each>
> </xsl:variable>
> <xsl:variable name="secondVar" select="exsl:nodet-set($secondVar-rtf)"/>

> > Here $firstVar operates on the source xml, and $secondVar works on the
> 'result' of the apply-templates in $firstVar.
>

> The final link in the chain is of course:
>

> <xsl:template match="/">
> <xsl:for-each select="$lastVar">

The same problem:

Must be:

<xsl:for-each select="$lastVar/node()">

Dimitre Novatchev.

I'm busy trying to figure this out....

Didn't do what I wanted it to, but I did learn something.

<xsl:variable name="firstVar-rtf">
  First
  <xsl:apply-templates />
</xsl:variable>
<xsl:variable name="firstVar" select="exsl:node-set($firstVar-rtf)"/>

<xsl:variable name="secVar-rtf">
Second
  <xsl:for-each select="$firstVar/node()">
    <xsl:copy-of select="."/>
    <xsl:apply-templates />
  </xsl:for-each>
</xsl:variable>
<xsl:variable name="secVar" select="exsl:node-set($secVar-rtf)"/>

<xsl:variable name="tripVar-rtf">
Third
  <xsl:for-each select="$secVar/node()">
    <xsl:copy-of select="."/>
    <xsl:apply-templates />
  </xsl:for-each>
</xsl:variable>
<xsl:variable name="tripVar" select="exsl:node-set($tripVar-rtf)"/>

<xsl:template match="/">
<div>
  <xsl:for-each select="$tripVar/node()">

    <xsl:copy-of select="."/>
    <xsl:if test="name()='h2'">
    skdlj
    </xsl:if>

    lakjdfkj
  </xsl:for-each>
  </div>
</xsl:template>

Standard XSL Standard Templates

I'm working on a set of standard XSL templates for web application interface markup.

They are called 1bb02b59 hosted at github.com and are licensed using the Apache 2.0 license, though I may switch or add the BSD or MIT licenses.

I'm also thinking about aligning up with the web-app-theme project for CSS and Javascript integration, though that appears to be RoR-centric.

The README.markdown file:

Standard General XSL Templates

Output Templates

  • Choose HTML4 strict, XHTML 1.0 transitional, or XHTML 1.1 strict

Usage

When using these templates, I use them like so:

<xsl:import href="http://github.com/docunext/1bb02b59/raw/master/output.xhtml10.xsl"/>
<xsl:include href="/path/to/xsl/html_custom.xsl"/>


<xsl:template match="/">
  <xsl:call-template name="page"/>
</xsl:template>

In this way, the imported stylesheet includes html_standard.xsl, which has templates for the interface components I regularly use.

The included stylesheet overrides those standard templates with ones specific to the application I am working on.

Extras

  • Source spacer: This is incredibly basic, but handy with HTML4 output
  • XHTML2DOM: I love this template. It converts XHTML to Javascript DOM.

Experimental

  • Link builder: can dynamic anchors be sensibly built from XML structures?