Archive

Posts Tagged ‘XML’

XML indentation in XSLT

August 23, 2008 1 comment

This my first XSLT script. I usually use DOM (either Java or Python API) for such things but I wanted to give XSLT a try.

<?xml version="1.0" encoding="ISO-8859-15"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml"/>

  <xsl:template match="@*">
    <xsl:copy/>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:value-of select="normalize-space(.)" />
  </xsl:template>

  <xsl:template match="*">
    <xsl:param name="indent" select="''"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:value-of select="$indent" />
    <xsl:copy>
      <xsl:apply-templates select="@*|*|text()">
        <xsl:with-param name="indent" select="concat($indent, '  ')"/>
      </xsl:apply-templates>
    </xsl:copy>
    <xsl:if test="count(../*)>0 and ../*[last()]=.">
      <xsl:text>&#xa;</xsl:text>
      <xsl:value-of select="substring($indent,3)" />
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
Tags: ,

XML Schema documentation generator

July 27, 2008 Leave a comment

One of the nicest advantage of using XML Schema is the automated documentation generation. First add annotations to your schema:

<xs:element name="Prout">
  <xs:annotation>
    <xs:documentation>This is a prout.</xs:documentation>
  </xs:annotation>
<xs:element>

Then use one of the following tool:

  • xs3p: An XSLT script. Its main advantage is that it’s create a documentation on one page. It’s nice to generate PDF files or integrate in Office documents.
  • xsddoc: It generate javadoc like documentation. Best for online documentation.

I did not found any other free as in speech tool.

Tags: ,