2012/01/05

Give me the tools ...

Succesful Resource Oriented is about composing small tools into a potent whole. Which sounds a bit like witchcraft, but it is not (well, most of the time it is not :-). It is however important to know the available tools. Here's something I cooked up in nCoDE not too long ago (click to image to get a decent look) :



Did you know about the netkernel:/ address space ? I did not, until I started wondering how the tools on the Backend HTTPFulcrum were created. Several of them are about modules and it is not like the 1060 Research people to do the same thing twice.

Only afterwards I discovered the documentation.

There are two lessons here :
1) Know the available tools. Search the documentation and if you can not find what you are looking for ... there is no shame in asking around.
2) When writing new tools (you will, it is inevitable), remember that our kind learns best through mimicry. Look at the available examples and learn from them.

For completeness, here are the xsl files from the example.
module.xml
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:nk="http://netkernel.org" 
                version="1.0">
  <xsl:output method="xml" 
              indent="yes" 
              encoding="UTF-8" 
              omit-xml-declaration="yes"/>
  <xsl:param name="moduleid" nk:class="java.lang.String" />


  <xsl:template match="/modules">
    <resultset>
      <xsl:copy-of select="module[id=$moduleid]"/>
    </resultset>
  </xsl:template>
</xsl:stylesheet>

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


  <xsl:output method="xml" 
              indent="yes" 
              encoding="UTF-8" 
              omit-xml-declaration="yes"
              media-type="application/xml"/>


  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
  
  <xsl:template match="@* | text() | comment() | processing-instruction()">
    <xsl:copy/>
  </xsl:template>
</xsl:stylesheet>

As to what my example does ... well ... you'll have to try it yourself, won't you ? Btw, the second XSLT in the example is not really necessary, nor is the XMLTidy step. I just like my results to be human-readable as well.