Silva altepeter.net Not logged in.

Family

Videos

Technology Stuff

Articles

Fun

Silva Products

Web Design

VIVO Javascript Framework

Photo Galleries

Contact Us

Blog

Using xslt to translate silva documents

Ok, I'm using an xslt stylesheet to upgrade the Silva Document xml for documents with Tropos version 1 forms  to Tropos version 2 forms.  I had already upgraded a couple sites, which apparrently worked fine.  On the last site I upgraded, none of the xslt would not catch the <form> tag.  I finally tracked it down to the <doc> tag in the xml.

The documents that correctly translated did not have a default namespace.  The documents that didn't had a doc tag like:

<doc xmlns="http://xml.infrae.com/document/0.9.3">

My stylesheet, which basically looked like:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">
  <xsl:output method="xml" version="1.0" indent="no" />
  <xsl:template match="form">
    <xsl:element name="form" use-attribute-sets="form-attrs">
    </xsl:element>
  </xsl:template>
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Did not work with documents that declared a default namespace.  To fix this, the stylesheet was modified to have two <xsl:template match="form"> blocks.  Because it was the default namespace, I didn't know how to make xsl:template match it.  So, I named the namespace in the xsl:stylesheet tag.  The new stylesheet looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:doc="http://xml.infrae.com/document/0.9.3"
                version="1.0">
  <xsl:output method="xml" version="1.0" indent="no" />
  <xsl:template match="form|doc:form">
    <xsl:element name="form">
    </xsl:element>
  </xsl:template>
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

And it works!